javascript - submit text box input using button - Stack Overflow

How do you submit text box input to a javascript function without submitting the server? <input type

How do you submit text box input to a javascript function without submitting the server?

<input type="text" id="test"  value="" />
<br/>
<button onclick="submitMe(value typed into text box)" id="testButton" >Submit Response</button>

Javascript:

function submitMe(input) {
    alert(input); //should output text box input
}

Thanks

How do you submit text box input to a javascript function without submitting the server?

<input type="text" id="test"  value="" />
<br/>
<button onclick="submitMe(value typed into text box)" id="testButton" >Submit Response</button>

Javascript:

function submitMe(input) {
    alert(input); //should output text box input
}

Thanks

Share Improve this question asked Jan 7, 2014 at 3:31 user3871user3871 12.7k36 gold badges140 silver badges282 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

No need to pass by parameter, just the the element by id.

function submitMe() {
    var value = document.getElementById('test').value;
    alert(value);
}

Or you could pass the id like:

<input type="text" id="test"  value="" />
<br/>
<button onclick="submitMe('test')" id="testButton" >Submit Response</button>

js:

function submitMe(id) {
    var value = document.getElementById(id).value;
    alert(value);
}

Try

<input type="text" id="test"  value="" />
<br/>
<button onclick="submitMe(document.getElementById('test').value)" id="testButton" >Submit Response</button>

DEMO

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

相关推荐

  • javascript - submit text box input using button - Stack Overflow

    How do you submit text box input to a javascript function without submitting the server? <input type

    8天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信