form submitting on enter key code example

Example 1: html disable enter submit

//per form disabling
<form ... onkeydown="return event.key != 'Enter';">
 
  
//or with jquery  
<script>
 $(document).on("keydown", "form", function(event) { 
    return event.key != "Enter";
});
 </script>

Example 2: javascript submit form when enter key pressed

//submit form when 'Enter' key is pressed while in myInputID
document.getElementById("myInputID").addEventListener("keyup", function(event) {
    if (event.keyCode === 13) {
    	document.getElementById("myFormID").submit();
		return false;
    }
});

Example 3: how to stop form from submitting on enter

<form ... onkeydown="return event.key != 'Enter';">

Example 4: how to send a form when you hit the enter key

use the "submit" feature instead of the "button" feature, I.E.

<input type="submit" value="login" onclick="password(this.password)">

Tags:

Html Example