I have a basic input field. When the page finishes loading I'd like to automatically focus on the input field, set a value, and finally trigger an 'enter' keypress without having a user trigger these events.
In the code below, the first two steps work fine, but the enter key is never triggered (I have an alert when it is triggered). Can anyone provide insight into how this can be accomplished?
$(document).ready(function () {
$("#myInput").focus();
var e = jQuery.Event("keydown");
e.which = 13;
$("#myInput").val("test");
$("#myInput").trigger(e);
});