0

i'm developing a website, but i'm not an expert when it comes to javascript. I'm using a script that i found on the internet for searching the page for a text string. To call this function i use the following code:

  <div class="pesquisa" id="pesquisa"><form name="f1" action=""
  onSubmit="if(this.t1.value!=null && this.t1.value!='')
  findString(this.t1.value);return false">
  <input name="t1" type="text" /></form>
  </div>

this is working well, when i enter text and click enter he finds it on the page. Now i have a "button" next to it that is represented by:

<a href='javaScript:document.f1.findString(this.t1.value)'>
<div class="enviar" id="enviar">Pesquisar</div></a></div>

I want this "button" to call the same function with the value inserted in the form. But it is not working this way. Any ideas on how this can be made ?

Thanks in advance, Cláudio

2 Answers 2

1

First, add an id attribute to the textbox:

<input id="t1" name="t1" type="text" />

Then, in your <a> tag, you can do this:

<a href="#" onclick="findString(document.getElementById('t1').value); return false;">Click Me</a>
Sign up to request clarification or add additional context in comments.

2 Comments

I did that you told me to do, but i get a "document.f1.findString is not a function" error.
Sorry about that. That was a copy-paste mistake on my part. See my edit.
0

Try this.. Add an id attribute to t1 (also called "t1"), and then reference it like this:

<a onclick="javaScript:findString(document.getElementById('t1').value)">

1 Comment

The main difference here over FishBasketGordo's answer is that you don't even need the href attribute, and therefore don't need to include return false to prevent the navigation from firing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.