This is my code
function searchForProductsInPopup(evt) {
var charCode = (evt.which) ? evt.which : evt.keyCode;
alert("in");
if(charCode == 27) {
closePopup();
}
else if(charCode == 13) {
closePopup();
return false;
}
}
HTML code
<input type="text"
class="input-medium focused"
id="invoiceSearchKeyWord"
onkeydown="return searchForProductsInPopup(event);"/>
This function will execute on the keyup event of a textbox, for all the other key my code will give an alert saying in. But when pressing Enter key I'm not getting any alerts and directly the form is submitted, why is that? My knowledge in JS is very limited. Can anybody explain?
The
submitevent is triggered before yourkeyupevent:https://jsfiddle.net/DerekL/pvw1dtb7/
You will see the expected
keyupevent if you properly prevent yoursubmitevent. Something like this:https://jsfiddle.net/DerekL/dmpxjt27/