Trigger an on click event to a HTML button when keyboard enter key press using JQuery
Trigger an on click event to a HTML button when keyboard enter key press using JQuery
HTML code part
<!DOCTYPE html> <html> <head> <!-- make sure to import JQuery library --> <meta charset=utf-8 /> <title>JS Bin</title> </head> <body> <input type="text" id="id_of_textbox" name=""> <input type="button" value="submit" id="id_of_button"> </body> </html>
JS code part
$( document ).ready(function() {
$(“#id_of_textbox”).keyup(function(event){
if(event.keyCode == 13){
$(“#id_of_button”).click();
}
});
if you have only one submit button in your page normally modern browsers trigger on click event when pressing the enter key no need a script for that . But if you have more than one button in your page you must have to define what button is going to click when press enter key .