c14kaa
c14kaa

Reputation: 903

submit form on 'enter' in IE "web browser"

having a problem with the number one browser for downloading another browser...IE

IE8 fails to submit when you hit enter in a form. here is what i use:

function submitOnEnter() {
    if (browserName=="Microsoft Internet Explorer")
    {
        var key;

        if (window.event){
            key = window.event.keyCode; //IE
        }

        if(key == 13){
          document.forms['myform'].submit();
        }
    }
}

and this is located on the text input :

 onkeyup="submitOnEnter()"

The form seems to submit when i press enter twice?? but not once.

Can you help?

Upvotes: 5

Views: 9051

Answers (3)

Alexander Wenzel
Alexander Wenzel

Reputation: 121

My problem was that i checked for the submit button. But IE seems not to send the submits in the $_POST array. Adding a hidden field solved my problem.

Upvotes: 2

c14kaa
c14kaa

Reputation: 903

Okay guys, i fixed it using....

  <!-- Fix for IE bug (One text input and submit, disables submit on pressing "Enter") -->    
  <div style="display:none">                 
  <input type="text" name="hiddenText"/>     
  </div> 

Weird eh? Maybe this will work for some of you and not others. some solutions didnt work for me, this one did.

Upvotes: 5

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114367

Submit works when pressing ENTER when there is a submit button present in the form <input type="submit">. You can hide the button if you want. No need to intercept keystrokes.

Upvotes: 3

Related Questions