I have a basic form
with a search input
and a submit button
within. When focus takes place in the input
, the keyboard is displayed as expected. When I press the button
, the form submit event occurs, in which I call event.preventDefault()
and instead make an ajax call. However, when I press the search button on the keyboard, the keyboard just hides and no submit event occurs.
Why doesn't the form submit when I press search on the keyboard? How can I trigger this event to happen via the keyboard search button?
Thanks.
The keyboard search button must be bound to a keypress event and has the keycode
of 13
.
Basically, listen to keypress
events and return all calls except for e.which === 13
$('input').on('keypress', function ( e ) {
if ( e.which !== 13 ) {
return;
}
// ajax code
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With