Saturday, December 29, 2012

Disable Enter Key event jquery java script

How to disable 'Enter Key' press key event using JQuery

As we know the default function of ENTER KEY is to submit HTML form values.

Sometimes we do not wish to submit the form values and want to do some other functionality. We can achieve this after disabling Enter Key press event and can call another event. The JQuery code sample is given here.

                        "Call any event of textbox when User press Enter Key"

   $("input").bind("keydown", function(event) 

     // track enter key
   var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which :    event.charCode));

     if (keycode == 13)         //Here 13 is the keycode for enter key
       // force the 'Enter Key' to implicitly call onchange event
        return false;
      return true;

                         "No action when User press Enter Key"

    return event.keyCode == 13 ? false : true; 


Powered by Code Imagine