Reputation: 12716
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
Upvotes: 1
Views: 13260
Reputation: 13839
Try
<input type="text" id="test" value="" />
<br/>
<button onclick="submitMe(document.getElementById('test').value)" id="testButton" >Submit Response</button>
Upvotes: 1
Reputation: 160943
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);
}
Upvotes: 3