I wrote a js and it look like
$('#searchform').keydown( function( event ) {
if ( event.which == '13' ) {
submitForm();
return;
}else if ( event.which == '27' ){
alert("ESC keydown TO DO - Clear the contents from search box ");
$('#id_search').val('');
}
});
This will remove contents of that input box, but when i comment alert message, it will not. Could you please explain me why??
OK, figured out what happens.
In Firefox browser, the flow of events is:
keydownevent handler is called, value is changed to empty string.In other words, you can’t directly change the value during
keydownevent.One simple workaround is using a timer, changing the value after a millisecond:
Updated fiddle.