So the code that I have so far is:
First of all add jquery library file jquery and call it in your html head.
and then Use jquery based code...
$("#id_of_textbox").keyup(function(event){
if(event.keyCode == 13){
$("#id_of_button").click();
}
});
You could add an event handler to your input like so:
document.getElementById('addLinks').onkeypress=function(e){
if(e.keyCode==13){
document.getElementById('linkadd').click();
}
}
$(document).ready(function(){
$('#TextBoxId').keypress(function(e){
if(e.keyCode==13)
$('#linkadd').click();
});
});
This should do it, I am using jQuery you can write plain javascript.
Replace sendMessage()
with your functionality.
$('#addLinks').keypress(function(e) {
if (e.which == 13) {
sendMessage();
e.preventDefault();
}
});
It works when input type="button" is replaced with input type="submit" for the default button which needs to be triggered.
button
with a submit
submit
handler of the form, not the click
handler of the buttonPressing enter in the field will trigger form submission, and the submit handler will fire.