Forum Moderators: open

Message Too Old, No Replies

Disabling "On Enter" submits form

Disabling "On Enter" submits form

         

Civichunter

11:58 pm on Oct 3, 2005 (gmt 0)

10+ Year Member



Hi Guys,

I know that most (if not all) browsers behave in a similar way such that when you are filling out a form and when you press the enter key, the form submits automatically.
Is there any chance that this can be disabled at all. This is potentially a problem when users tries to enforce a carriage return in a text field by press enter but instead submits the unfinished form.
Any feedback is really appreciated guys.

Thanks

Eltiti

12:16 am on Oct 4, 2005 (gmt 0)

10+ Year Member



One way to solve the problem might be to use a validation function that returns "true" if all required fields have been entered, or "false" otherwise. Would that work for you?

dcrombie

2:52 pm on Oct 4, 2005 (gmt 0)



What Eltiti said is a better approach, but this should also work:

<form ... onSubmit="return false;"> 
...
<input type="button" value="Submit" onClick="this.form.submit();">
</form>

;)

kaled

3:59 pm on Oct 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Assuming javascript is enabled, don't use a submit button. Use a standard button and submit the form using its onclick event. However, if javascript is disabled you'll need a standard submit button. ie

1) Use document.write() to create the standard button.
2) Place a submit button within <noscript></noscript>.

Kaled.