I have input text
within form
, however I do not want form
to be typed ENTER . The code below works, but if I uncomment the alert
the form
is submitted even with the two lines below. Can anyone explain me why?
$(document).ready(function() {
$('#txtPesquisaServidor').keydown(function(event){
if(event.keyCode == 13) {
//alert('enter!');
event.preventDefault();
return false;
}
});
});
I'm using jQuery 1.6.2
EDIT 1
The alert
is only illustrative, by typing ENTER the input
will have the same behavior as the click of the button link
EDIT 2
I got it! If I were to use alert
, I would have to set timeout
or use stop()
so that the code would not be confused, thus sending form
(which was not what I wanted). The problem, in fact, does not exist without alert
. I just put my original code to test and it worked fine.
Code working: link
Thanks to all who contributed.