html button press enter off

Solutions on MaxInterview for html button press enter off by the best coders in the world

showing results for - "html button press enter off"
Mercy
07 Apr 2018
1Explicit Prevention:
2
3<form>
4    <label for="name">Name:</label>
5  	//Not able to press `Enter`
6    <input type="text" name="name" onkeypress="ExplicitPrevention(event)">
7  	//Able to press `Enter`
8    <input type="submit" value="Submit">
9</form>
10
11<script>
12    const ExplicitPrevention = function (event) {
13      	var keyPressed = event.keyCode || event.which;
14      	if (keyPressed === 13) {
15          	alert("Test: You pressed the Enter key!!");
16        	event.preventDefault();
17      	}
18    }
19</script>
20
21//Also check: https://www.tjvantoll.com/2013/01/01/enter-should-submit-forms-stop-messing-with-that/
22//and: https://www.geeksforgeeks.org/how-to-disable-form-submit-on-enter-button-using-jquery/