Tuesday, December 15, 2009

Submit a Form in HTML Using the Enter Key

Join GeekyClown's Fan Page on Facebook | Follow me on Twitter
Today I was writing a quick form to transfer a person's e-mail address to another page where I was going to look up the user based on that e-mail.  The page took all of five minutes to write and I went ahead and did my data manipulation, etc. on the subsequent page.  Got the application completed and shipped it off to the powers that be for approval.  The first note I got back, the e-mail address form doesn't submit when the 'Enter' key is pressed.

I looked at the code:
<form name="ReqPassowrd" method="post" action="mysubsequentpage.cfm">
<b>Please put your e-mail address:</b><br>
<input type="text" name="EmailAddress">
<br>
<input type="submit" name="submit" value="submit">
</form>

Works perfectly well in Chrome and FireFox.  The default should kick in that either clicking the 'Submit' button or pressing 'Enter' on the keyboard should submit the form.  However, it appears Internet Explorer doesn't allow this - especially the dreaded Internet Explorer 6 (which is what was being used by the individual who let me know of the issue).  I did a little research and found others having the same issue and read about 25 different solutions.  In the end, I had to combine several and came up with using an invisible input tag.  That is right, an invisible tag that more or less is tricking the browser.

After the input tag for the e-mail, I had to put in the following:
<input name="doesntmatter" type="none" style="display:none">

Then the form will submit.  Yet shows once again the IE is buggy.  If you are using Internet Explorer 6 - please, do us all a favor, UPGRADE!!!!

No comments:

Post a Comment