HTML form does not submit in IE on Enter Key

Discussions on HTML - HyperText Markup Language
Forum rules
You may post any technical questions you have on HTML Topic here.
Irrelevant topics will be deleted/moderated without prior notice.
Do not start multiple threads on the same topic

HTML form does not submit in IE on Enter Key

Postby htmlbabe on Wed Sep 30, 2009 8:44 pm

I have a strange problem in IE! :cry:

I created a form which has 5 input fields and a submit button. A javascript function validates the form on submit event.

The Problem:
In firefox, when I press "Enter" Key, the form gets submitted and the validation function works. But In IE browsers, when "Enter" key is pressed, nothing happens (It does not submit the form) :( .

Please Help... Thanks in Advance.
htmlbabe
 
Posts: 1
Joined: Wed Sep 30, 2009 8:36 pm

Re: HTML form does not submit in IE on Enter Key

Postby shivaprasad on Thu Oct 01, 2009 1:08 pm

Hi,

Try the following :

Step 1:
Define the following JavaScript function:

Code: Select all
<script type="text/javascript">
function pressedKey()
{
   if(event.keyCode==13)
   {
      /*document.getElementById("same as your submit button's id").focus();*/
      document.getElementById("SubmitButton").focus();
   }
}
</script>

Step 2:
Add the following in your form(onkeypress="pressedKey();) tag:
Code: Select all
<form name="yourfromname" action="youraction" target="_parent" id="yourfromname" method="post" onsubmit="return validateForm(this);"  onkeypress="pressedKey();">
/*Form Input fields 1*/

/*Form Input fields 2*/

<input name="SubmitButton" id="SubmitButton" type="submit" title="Submit this form" />

</form>

Important: The submit button id should be the same as defined in the function(Step1)

That's it........... :geek:
Shivaprasad
shivaprasad
 
Posts: 1
Joined: Thu Oct 01, 2009 12:17 pm


Return to HTML



Who is online

Users browsing this forum: No registered users and 1 guest

cron