Ethannn
Ethannn

Reputation: 191

JS | After onkeypress an Onclick event is fired in IE10

<button type="submit" id="button" onclick="btnClick()">ADD</button>
<input type="text" id="prefix" placeholder="type" onkeypress="process(event)">

function process(e) {
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 13) {
alert("INPUT");
}
}

function btnClick() {
alert("BUTTON");
}

There is an input box and button. The user should be able to enter data by using the button or use the enter key inside the input box.

This all works in Chrome, IE Edge, but errors in IE10. In IE10 when the user hits the enter button, it fires the inputbox event code, and then executes the code for the button as well.

Jsfiddle

Upvotes: 1

Views: 153

Answers (1)

Ethannn
Ethannn

Reputation: 191

Changing the type attribute to type="button" solved it

Upvotes: 2

Related Questions