I am trying to simulate an enter keypress for an input on page load, however it doesn't appear to be working. I only find success when I click in the input and press enter. I expect to see the alert when the page loads.
If you change the order I have listed below, then it provides an alert, but the key that is pressed is undefined.
Any ideas where I am going wrong here?
See demo here - http://jsfiddle.net/3xTM2/1321/
HTML
<input id="test" type="text" />
Javascript
$('#test').trigger(jQuery.Event('keypress', { keycode: 13 }));
$('#test').keypress(function(e) {
alert(e.keyCode);
});