JQuery "event not defined" error on simulated keystroke

I'm currently trying to use jquery to enter selection from a drop-down list into a text box, simulate a click to select it, press return, wait for some processing, and then press return again. This is a pretty nasty way to get what I need, but this is the only way I can see at the moment. Here is the code:

$('#fav').change(function() 
{
  $('#contract_input').val($('#fav').val());
  $('#contract_input').trigger('click');
  e = jQuery.Event("keypress");
  e.which = 13;
  $('#contract_input').trigger(e).delay(500).trigger(e);
}

The problem I am facing is that IE8 gives an error message on the page:

"Event" not defined

Click seems to work, it's just a return that doesn't.

Any ideas?

Thanks a lot Cap

+3
2

keydown keypress, IE e.keyCode e.which.

.

e = jQuery.Event("keydown");
e.keyCode = 13;
$('#contract_input').trigger(e).delay(500).trigger(e);
+1

: $ ('# contract_input'). keypress (function (e) {do Stuff}); http://api.jquery.com/keypress/

-1

Source: https://habr.com/ru/post/1769105/


All Articles