Skip to content Skip to sidebar Skip to footer

Why Cant I Press Enter Programatically?

I'm trying to fire off a search programatically having populated the input. Can't find a clear Javascript example of that though. Jquery not really an option as i want to keep this

Solution 1:

You could also put the input in a form element and then call form.submit() on the form element.

Solution 2:

Pressing even is triggering an event you need to find what event the code is listening to the below would work for keyup event

var evt = new CustomEvent('keyup');
evt.which = 13;
evt.keyCode = 13;
input.dispatchEvent(evt);

Have a look at this answer it might help https://stackoverflow.com/a/29720843/13335890

Post a Comment for "Why Cant I Press Enter Programatically?"