Prevent submit for "ENTER" in particular text field
Hey. I was wondering whether there was a good way to prevent a form from being submitted when the User hits the "Enter" key within a particular text field. I am just not sure whether the code below will work on all browsers and system - maybe a system identifies the Enter key as 0x0a or whatnot. And I'd prefer to have it all in a single event handler.
Right bow my code looks like this:
- // $("#searchField") is a text input element
- // and $("#f") is a form element around prior element
- var blockSubmit;
- $("#searchField").keydown(function(event){
- if(event.which == 0x0d) {
- blockSubmit = true;
- sparteBoxChanged();
- }
- });
- $("#f").submit(function(){
- if(blockSubmit) {
- blockSubmit = false;
- return false;
- } else {
- return true;
- }
- });