How to disable auto submit behavior when hitting enter key?
button, javascript
Solution
This function should do the trick:
function submitOnEnter(e, page) {
var key;
if (window.event)
key = window.event.keyCode; //IE
else
key = e.which; //Firefox & others
if(key == 13)
window.location = page;
}
You should call it like this:
<input id="Text2" type="text" onkeyup="submitOnEnter(event, 'p2.html')" />
Problem
I want to hit enter key to go to p2.htm or p3.htm according to the input text that I was typing in. And I also want to hit submit1 button to alert('no1') manually. It works in FireFox, but in IE6, when I hit enter key it will submit the submit button. How can I make the thing right in IE 6 as it is in FireFox? I use javascript and jQuery. ``` <input id="Text2" type="text" onkeyup="if(event.keyCode==13){go2();}" /> <input id="Text3" type="text" onkeyup="if(event.keyCode==13){go3();}" /> <input id="submit1" type="submit" value="submit" onclick="alert('no1')" /> <script type="text/javascript"> function go2() { window.location = "p2.htm"; } function go3() { window.location = "p3.htm"; } </script> ```