0

I have a form with a text input.

I managed to prevent ENTER from submitting the form by doing this:

jQuery("#inputTags").keydown(function(event) {
      if (event.keyCode == '13') {
         event.preventDefault();

         tagManagerCreate(true);

         return false;
      }
    });

tagManagerCreate() does some stuff. Sometimes, this function triggers a javascript "alert". For some reason when that happens, the form still gets submitted!

Nathan H
  • 46,253
  • 59
  • 160
  • 244
  • For design purposes I changed to the jQuery-UI dialog, and it fixed it. But I guess the question is still relevant for others – Nathan H Aug 18 '11 at 14:56

2 Answers2

2

I think you should use .keypress instead of .keydown

http://api.jquery.com/keypress/

http://api.jquery.com/keydown/

and what the tagManagerCreate(true); do?

zod
  • 11,702
  • 23
  • 66
  • 104
  • I think that was it. I'll test again with alert (since i removed it) and let you know. tagManagerCreate makes an ajax calls and sometimes triggers an alert based on the result – Nathan H Aug 20 '11 at 17:17
0

Can you try to wrap tagManagerCreate(true); in a try/catch block and see?

try{

   tagManagerCreate(true);

}catch(e){}
ShankarSangoli
  • 68,720
  • 11
  • 89
  • 123