3

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?

M3rlino
  • 671
  • 1
  • 8
  • 19

3 Answers3

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.

Community
  • 1
  • 1
cletus
  • 599,013
  • 161
  • 897
  • 938
  • 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
  • 1
    What 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,314
  • 1
  • 30
  • 29
2

Lots of discussion about this here: How to prevent ENTER keypress to submit a web form?

Community
  • 1
  • 1
DanSingerman
  • 35,232
  • 13
  • 78
  • 92