admin管理员组

文章数量:1026103

I have 2 text areas in my page as;

<input type="text" id="a1"/>
<textarea id="b2"></textarea>
<a id="button">button</a>

When user click the button link, I want to alert the data entered in a1 and b2.

How can I do this?? Here is there demo

Thanks in advance...:)

blasteralfred

I have 2 text areas in my page as;

<input type="text" id="a1"/>
<textarea id="b2"></textarea>
<a id="button">button</a>

When user click the button link, I want to alert the data entered in a1 and b2.

How can I do this?? Here is there demo

Thanks in advance...:)

blasteralfred

Share Improve this question asked Apr 12, 2011 at 6:41 AlfredAlfred 21.4k63 gold badges174 silver badges257 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5
  $(document).ready(function() {
    $('#button').click(function(e) {
      e.preventDefault();
      alert($('#a1').val());
      alert($('#b2').val());
    });
  });

dont use same id a1 for <a id="button">button</a> and <input type="text" id="a1"/>

and you can use jquery val() function to get value

alert($('#a1').val());
alert($('#b2').val());

Do like this :

window.alert($("#a1").val());
window.alert($("#a2").val());

Your code should appear likt this :

<input type="text" id="a1"/>
<textarea id="b2"></textarea>
<a id="button" onclick="window.alert($('#a1').val());window.alert($('#a2').val());return false;">button</a>

I have 2 text areas in my page as;

<input type="text" id="a1"/>
<textarea id="b2"></textarea>
<a id="button">button</a>

When user click the button link, I want to alert the data entered in a1 and b2.

How can I do this?? Here is there demo

Thanks in advance...:)

blasteralfred

I have 2 text areas in my page as;

<input type="text" id="a1"/>
<textarea id="b2"></textarea>
<a id="button">button</a>

When user click the button link, I want to alert the data entered in a1 and b2.

How can I do this?? Here is there demo

Thanks in advance...:)

blasteralfred

Share Improve this question asked Apr 12, 2011 at 6:41 AlfredAlfred 21.4k63 gold badges174 silver badges257 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5
  $(document).ready(function() {
    $('#button').click(function(e) {
      e.preventDefault();
      alert($('#a1').val());
      alert($('#b2').val());
    });
  });

dont use same id a1 for <a id="button">button</a> and <input type="text" id="a1"/>

and you can use jquery val() function to get value

alert($('#a1').val());
alert($('#b2').val());

Do like this :

window.alert($("#a1").val());
window.alert($("#a2").val());

Your code should appear likt this :

<input type="text" id="a1"/>
<textarea id="b2"></textarea>
<a id="button" onclick="window.alert($('#a1').val());window.alert($('#a2').val());return false;">button</a>

本文标签: javascriptget text area and text field datajqueryStack Overflow