disable Input submit form on enter but enter values on enter

Viewed 31

I have The Following lines of code, when I attempt to enter an amount in the input division and hit enter, it automatically submits the form,

I need the input to change the amount when i Hit enter without submitting the form automatically only when i click on the submit button

how do I change My Lines Of code?

<input id="stake" type ="number" name="stake[]" value="5">

<input class="bet1" type="submit" name="submit" value="Bet">

1 Answers

Add an onkeyup listener to the number input.

Return false if the keyCode on the event is 13, which is the code for the enter key.

<input id="stake" type ="number" name="stake[]" value="5" onkeypress="preventSubmissionOnEnter(event)">

<script>
function preventSubmissionOnEnter(e) {
   if (e.keyCode === 13) {
        e.preventDefault();
   }
}
</script>
Related