简体   繁体   中英

submit text box input using button

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM