•  0
    JavaScript

    Disable form submit on Enter Key using Javascript and JQuery

      Asmin Jismun    241        0        Report content

    Disable form submit on Enter Key for textbox in Javascript and JQuery.

    Create the function to disable the enter key event

    function disableEnterKey(event) {
            event = event || window.event;
            if (event.keyCode == 13) { 
                event.cancelBubble = true;
                event.returnValue = false;
                // Firefox.
                if (event.preventDefault) {
                    event.preventDefault();
                }
            }   
        }
    

    Then call the function in onclick attribute

     

    Alternatively, the form will be submitted on keypress by default if the form consist only one textbox. To disable this, just add hidden input as shown below:

     

     


  •  


Leave a Comment

Please Login to insert comment.

 

Facebook Conversations