最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - get text area and text field data - jquery - Stack Overflow

matteradmin5PV0评论

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>
Post a comment

comment list (0)

  1. No comments so far