views:

34

answers:

3

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?

+2  A: 

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.

Pekka
+1 "Enter" to submit is default behavior inside text fields.
Adam Backstrom
@Adam yup. IIRC in IE, a "submit" button needs to be present for it to work, so adding that should do the trick
Pekka
I was looking for the way if i can make it happen by using "type="button""...
OM The Eternity
@OM it's certainly possible but then you need to put the event on the text fields, as said by others. Any special reason why you can't use `submit`?
Pekka
Just being Different!!!!
OM The Eternity
@Om that is not clever, because you are creating an additional, unnecessary dependency on JavaScript. `type="submit"` will work with JS turned off
Pekka
A: 

You should move the onkeydown event to the text fields rather than having it on the button control.

spinon
A: 

In addition to spinons answer you could observe the onkeydown of the whole form:

<form onkeydown="(function(event,form){if(event.keyCode == 13){form.submit();}})(event,this)" name="login" action="" method="post">
Dr.Molle