When I’m in certain text fields I want to be able to stop the propagation of the “enter” keypress.
Basically as long as I’m certain inputs I don’t want the form that they’re in to submit, and I need to intercept it. (The form is split into “windows”. If they’re not in the last window (.win2) then I don’t want them to be able to hit enter and submit the form without realising they’re only on the first window.
I hope that makes sense.
Here’s what I have:
$(".win1 :input").keyup(function(e){
if(e.which === 13){
return false;
}
});
Unfortunately this doesn’t work. The keyup event gets fired, but I don’t think that the return false works appropriately. Using e.preventDefault(); e.stopPropagation(); doesn’t work either. Is there an easy way to stop the submit event from triggering on the form by listening to “enter” key presses?
Thanks
You can replace your input type=”submit” by a normal button, which will do something like
$("form").submit();if the data is legal, and otherwise the submit is never triggered.Normally this should work: