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>
getElementById("testForm"); form. addEventListener("submit",function(e){e. preventDefault(); return false;}); This solution will now prevent the user from submit using the enter Key and will not reload the page, or take you to the top of the page, if your form is somewhere below.
type="submit" is the default (as specified by the HTML spec): The missing value default and invalid value default are the Submit Button state. Show activity on this post. Also, if you use type="button" your form will not be submitted.
If using MVC3, you can disable submitting via Enter by editing the BeginForm call as follows:
@using (Html.BeginForm("SomeAction", "SomeController", FormMethod.Post, new { onkeydown = "return event.keyCode!=13" }))
{
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With