Search code examples
phpjavascriptonkeydown

I have a login form with an event of clicking the enter key to submit the form, it is not working in IE


I have a login form with an event of clicking the enter to submit the form, it is not working in IE

<form name="login" action="" method="post">
<ul>
    <li class="col1">E-mail Address</li>
    <li class="col2"><input name="email_address" type="text" class="textfiled" /></li>
    <li class="col1">Password</li>
    <li class="col2"><input name="password" type="password" class="textfiled" /></li>
    <li class="col1"></li>
    <li class="col2"><input name="signin" type="button" class="signin-btn" onclick="javascript: login.submit();" onkeydown="javascript: if (window.event.keyCode == 13) login.submit(); else window.event.keyCode = null;"/></li>
</ul>
</form>

Here on submit button i have mention an event as onkeydown="javascript: if (window.event.keyCode == 13) login.submit(); else window.event.keyCode = null;"

This is not working in IE, can someone suggest me any solution for this or any alternative of solution i have applied for my requirement?


Solution

  • Any reason why you're not using a simple

    <input type="submit">
    

    ?

    It should enable the "enter to submit" behaviour in all browsers without having to use JavaScript at all.