I have one form with several text fields and one button. When i enter one of the text fields, the submit button become highlighted and if i press enter while typing, the button is pressed, so i got an unexpecte behaviour because my page is submitted. Firefox doesn't act such a way.
Is there some attribute or configuration to avoid this undesired behaviour or i have to use some javascript technique?
Asked
Active
Viewed 1,454 times
3

M3rlino
- 671
- 1
- 7
- 20
3 Answers
4
Generally what I do in this situation is make the first button on the form do nothing and then hide it with CSS. Kludgy? Sure. Effective? Absolutely.
In fact, this is a duplicate of Stopping IE from highlighting the first submit-button in a form.
-
I think the solution should be extended with the fact that the button should have onclick ="return false;" and also it should be hidden with width:0px. – M3rlino Jul 06 '09 at 15:22
-
1What benefit is width:0px over display:none? – cletus Jul 06 '09 at 22:51
2
You need to disable the Enter key for those input elements to prevent form submission. Take a look at this article.

Peter
- 6,354
- 1
- 31
- 29
-
It could be a good solution. In my case i preferred to use cletus'solution. – M3rlino Jul 06 '09 at 15:11
2
Lots of discussion about this here: How to prevent ENTER keypress to submit a web form?

Community
- 1
- 1

DanSingerman
- 36,066
- 13
- 81
- 92