Call javascript function with an href - Stack Overflow

i'm developing a website, but i'm not an expert when it es to javascript. I'm using a sc

i'm developing a website, but i'm not an expert when it es 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

i'm developing a website, but i'm not an expert when it es 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

Share asked Jul 2, 2011 at 13:40 Cláudio RibeiroCláudio Ribeiro 1,6993 gold badges42 silver badges66 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 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>

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)">

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745071588a4609581.html

相关推荐

  • Call javascript function with an href - Stack Overflow

    i'm developing a website, but i'm not an expert when it es to javascript. I'm using a sc

    23小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信