Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form submits when pressing enter from text field

Status
Not open for further replies.

NeeNee

Programmer
Apr 2, 2002
97
CA
I have a simple form with one text field and a button. Now the button uses the onclick event with javascript to submit the form because I did not want the users to submit the form when pressing enter, which is the case with submit buttons.

If I do not focus on the text field and press enter, nothing happens which is what I want, but if I put the focus in the text field and press enter, the form is submitted but no information is passed.

I have used this technique in all my pages to control the users use of the enter button.

Any ideas why this is happening?



Denis
Programmer, Canada
 
I imagine you have an onsubmit handler which does something, and because this isn't being called, your form is submititng empty data (onsubmit handlers are never run if you programatically submit a form).

Out of interest, why do you want to dictate to users how they submit their form? Wouldn't the nice thing to be to leave the behaviour down to the browser so users can have a consistent experience with other sites they use?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Because we have a mixture of Cobol where the user has to press enter to move to the next field and web where the user has to press tab to move to the next field.

We found that those users kept pressing enter before they were done completing a form.

I don't use onsubmit. I place all my validation in the function that I write attached to the custom submit button.

I did find that when I added a second text field, the form stopped submitting when pressing enter from the text box. So I place a text box with hidden borders and it now works fine.

Thanks.

Denis
Programmer, Canada
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top