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
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>
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)">
精彩评论