xxxxxxxxxx
var e = jQuery.Event("keydown");
e.which = 13; //choose the one you want
e.keyCode = 13;
$("#theInputToTest").trigger(e);
xxxxxxxxxx
//jQuery detect user pressing enter
$(document).on('keypress',function(e) {
if(e.which == 13) {
alert('User pressed Enter!');
}
});
xxxxxxxxxx
$('#textbox').keypress(function(event){
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == '13'){
alert('You pressed a "enter" key in textbox');
}
});
jquery on enter keypress
xxxxxxxxxx
// Lets pressing Enter be interpreted as a click
$('.thingy').keypress(function(event) {
if (event.key === "Enter") {
event.preventDefault();
this.click();
}
xxxxxxxxxx
$('#jenis_diet_baru').keypress(function(event){
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == '13'){
console.log('works');
}
});
xxxxxxxxxx
$('#someTextBox').keypress(function(event){
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == '13'){
alert('You pressed a "enter" key in textbox');
}
});