Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to manually invoke "Enter key" event on a textbox?

I want to manually invoke enter key press event on textbox through JS or jQuery.

I dont want to capture that event. I just want to invoke enter key press event.

like image 257
Aditya K Avatar asked Dec 22 '11 18:12

Aditya K


1 Answers

You can trigger it like:

// dummy event listener
$("input").keydown(function() { return true; });

var keyEvent = jQuery.Event("keydown");
keyEvent.keyCode = 13;
$("input").trigger(keyEvent);

See this post too: Definitive way to trigger keypress events with jQuery

like image 68
techfoobar Avatar answered Nov 01 '22 01:11

techfoobar