Enter does not submit form in IE because of hidden button
Asked Answered
M

4

9

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?

Mockingbird answered 23/8, 2010 at 9:14 Comment(3)
why have you got a hidden button?Tadeas
When Javascript is on, the form automatically submits when a user selects a value from a listbox, and the button is hidden. When Javascript is off, the user can use the button to submit the form after selecting a value.Mockingbird
I find the answers to this questions a wonderful insight into practical web development...Bangle
A
6

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.

Antislavery answered 23/8, 2010 at 9:50 Comment(0)
C
12

Try to hide button with following class:

.hidden-element {
  width: 0px;
  height: 0px;
  position: absolute;
  top: -99999px;
  left: -99999px;
}
Coridon answered 8/1, 2015 at 13:59 Comment(2)
It's a bit late to add an answer to a 1+ year old post, while there is already an accepted answer..Ddene
@Ddene I would disagree. Other people might find this particular comment helpful.Polyethylene
A
6

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.

Antislavery answered 23/8, 2010 at 9:50 Comment(0)
L
5

I fixed it by opacity 0 like:

<input type="submit" style="width: 0px; height: 0px; opacity: 0;" id="submitBtn" name="submitBtn">
Laetitia answered 9/10, 2015 at 23:25 Comment(0)
P
0

You can add additional button to retain submit button functionality in following way:

<![CDATA[<!--[if IE]>]]>
                <input type="text" style="display: none;" disabled="disabled" size="1" />
            <![CDATA[<![endif]-->]]>
Pierides answered 27/1, 2012 at 17:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.