I'm using PHP to pass a login form when required, and here is the code:
$htmlForm = '<form id="frmlogin">'.'<label>';
switch(LOGIN_METHOD)
{
case 'both':
$htmlForm .= $ACL_LANG['USERNAME'].'/'.$ACL_LANG['EMAIL'];
break;
case 'email':
$htmlForm .= $ACL_LANG['EMAIL'];
break;
default:
$htmlForm .= $ACL_LANG['USERNAME'];
break;
}
$htmlForm .= ':</label>'.
'<input type="text" name="u" id="u" class="textfield" />'.
'<label>'.$ACL_LANG['PASSWORD'].'</label>'.
'<input type="password" name="p" id="p" class="textfield" />'.
'<center><input type="submit" name="btn" id="btn" class="buttonfield" value="Sign in to extranet" /></center>'.
'</form>';
return $htmlForm;
The problem is, is that when the user hits enter in IE8, the form does not submit, and the user is forced to hit the submit button.
How do I rectify this?
Here is a link in Microsoft on it which might shed some light for you.
Taking a quick read of the link it might actually be considered a bug submitting the form by the Enter Key, which I presume would of been fixed by Microsoft for IE8.
IE anomaly when using the enter key to submit a form
Edit:
This has now been removed but another link covering it again (bottom of page) which defined it and explaining the bug in IE Blog on December 18th 2008.
Also watch out for this fun fun bug:
I've learned the hard way that if your form is
display:none
at page load, even if you show it later with Javascript, IE8 still won't submit on enter. However, if it's not hidden at page load, and you set it todisplay:none
after, like onDOMReady, then it works! WTFMore details and workaround here: http://www.thefutureoftheweb.com/blog/submit-a-form-in-ie-with-enter
Simulate a click
Here's how I do it in jQuery.
If this is a real problem and you can't find another solution you can always do an
onkeypress
event for the form and check if the Enter key was pressed.EDIT: Here's the correct code according to Machine's answer:
EDIT 2: Your HTML is valid. Try this:
Do you have an opening form tag that was just omitted from your code snippet?
I was able to reproduce this as well with an action and method. Stripped out all other code on the page and it still gets produced. However, I have seen forms work in IE8 with action=""