Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enter does not submit form in IE because of hidden button

I have a form with two buttons. The first is hidden using Javascript.

When I press enter in a textfield in IE, the form does not submit. I assume it is because it has chosen the first button as default submit button, but since that button is hidden it does not work.

I have solved this by submitting the form on an enter keydown Javascript event. However, this also submits the form if the user presses enter to select an item from the browser's autocomplete dropdown.

example autocomplete dropdown

How do I submit the form on enter in IE, without disturbing the autocomplete functionality?

like image 835
Sjoerd Avatar asked Aug 23 '10 09:08

Sjoerd


People also ask

How do I get submit button to work in Enter?

Enter = SubmitIf you have focus in the textbox and hit enter, the form will be submitted automatically. This behavior is consistent across all browsers and is known as implicit submission.

Why the submit button is not working?

Sometimes the problem is caused by old versions of the Javascript files, cached by your browser and can be fixed by clearing the browser cache. You can use the browser console of your browser for debugging. After the Javascript error is fixed, the submit button will automatically be enabled.

Do not submit form Enter key?

Disallow enter key anywhereon("keydown", "form", function(event) { return event. key != "Enter"; }); This will cause that every key press inside the form will be checked on the key .

Can I submit form with Button?

You can tie a submit button to a form that the button doesn't live inside of. The trick is to give the form an id and then reference that id with the button's form property. With this setup, clicking the Submit button will cause the form to be submitted.


2 Answers

Try to hide button with following class:

.hidden-element {
  width: 0px;
  height: 0px;
  position: absolute;
  top: -99999px;
  left: -99999px;
}
like image 147
Alla Avatar answered Sep 30 '22 13:09

Alla


We had a similar problem a few years ago, and AFAIR, we added an additional button to the beginning of the form, which always performs the default submit action when enter is pressed in IE. That button can be "almost hidden" by giving it a 1x1 transparent image.

like image 38
Chris Lercher Avatar answered Sep 30 '22 12:09

Chris Lercher