views:

159

answers:

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?

+4  A: 

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.

cletus
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
What benefit is width:0px over display:none?
cletus
+2  A: 

You need to disable the Enter key for those input elements to prevent form submission. Take a look at this article.

Peter
It could be a good solution. In my case i preferred to use cletus'solution.
M3rlino
+2  A: 

Lots of discussion about this here: http://stackoverflow.com/questions/585396/how-to-prevent-enter-keypress-to-submit-a-web-form/

DanSingerman