Usually when you press enter on the HTML form text fields, form gets submitted. If you don't want to submit the form when user clicks submit, you need to tell the browser to disable this default functionality. i.e.; you should disable the enter key for HTML form.

To implement this logic, simply you should include the below script on the page.

//Disabling the enter button on the form
function stopEnterKey(evt)
var evt=(evt)?evt:((event)?event:null);
var node=(;
if((evt.keyCode == 13) && (node.type=="text")) {return false;}
//13 is the ascii for enter and if you want another type of element change text to password, radio etc
document.onkeypress = stopEnterKey; //Invoking this on key press

The above script will disable the enter key for all the text fields. If you want this to be disabled for a different input element type, change the node.type to password or radio or remove this condition if you would like to fire this for all types of input elements.

This has been tested on IE 6 and 7, Firefox 2.0 and 3.0, Google chrome, Safari.

You can read my other Javascript articles