how to disable ENTER within FORMs ?

A

Albert

hallo everybody,

when i have a form in html, filled with some entry fields, and i press
ENTER, the form is always being sent (to what is defined in action=
.....). can i disable this feature, so that the form is only sent by
clicking the submit-button and not hitting ENTER somewhere ?
i'm very interested in plain html-solutions not using javascript.

many thanks in advance

albert
 
T

Toby A Inkster

Albert said:
when i have a form in html, filled with some entry fields, and i press
ENTER, the form is always being sent (to what is defined in action=
....). can i disable this feature, so that the form is only sent by
clicking the submit-button and not hitting ENTER somewhere ?

No you can't. And why would you want to? It's a very useful browser
feature.
 
M

Mark Parnell

hallo everybody,
G'day.


when i have a form in html, filled with some entry fields, and i press
ENTER, the form is always being sent (to what is defined in action=
....).

Would you expect it to do anything else?
can i disable this feature, so that the form is only sent by
clicking the submit-button and not hitting ENTER somewhere ?
i'm very interested in plain html-solutions not using javascript.

No, you can't. And why would you want to? What if the user doesn't have
a mouse? How are they supposed to submit the form?
 
A

Albert

Toby said:
Albert wrote:




No you can't. And why would you want to? It's a very useful browser
feature.

some people try to reach the next input field by pressing enter. this
would immediately send the form. i want the user to send it only by
clicking on the appropriate button (without using javascript), after
he/she has reached the end of the form.
ok, so i have to accept this although i don't like it.

thank you very much.

albert
 
M

Mark Parnell

some people try to reach the next input field by pressing enter.

Really? I have never seen anyone try to do that. Most will probably use
the mouse, or if they do use the keyboard, they know to use tab, the
same as in most programs.
 
J

Jukka K. Korpela

Albert said:
some people try to reach the next input field by pressing enter.
this would immediately send the form.

Then they will have to learn how their browser actually works.
I don't think you can help them much by slowing down the learning
process a little, and maybe even confusing them (into thinking that
what they see on your page is normal).
i want the user to send it
only by clicking on the appropriate button

You cannot. You can (and indeed should) deal with it when it happens.
Actually, even if you could prevent ENTER from submitting, people could
still submit incompletely filled-out forms. So your form handler needs
to be prepared to dealing with that.
 
V

Vladdy

Albert said:
hallo everybody,

when i have a form in html, filled with some entry fields, and i press
ENTER, the form is always being sent (to what is defined in action=
....). can i disable this feature, so that the form is only sent by
clicking the submit-button and not hitting ENTER somewhere ?
i'm very interested in plain html-solutions not using javascript.

many thanks in advance

albert
What you can do for users with enabled javascript is process onsubmit
event of the form and have that function return false if there is data
missing. This will prevent form submission when there are empty fields left.
Be advised that such function should bring users attention to the field
that triggered error, so that your page does not appear "brocken"
 
L

Leif K-Brooks

Albert said:
some people try to reach the next input field by pressing enter. this
would immediately send the form. i want the user to send it only by
clicking on the appropriate button (without using javascript), after
he/she has reached the end of the form.

If a user doesn't know how to use a browser, that's the user's fault. I
don't want to have to take my hands off of the keyboard when submitting
a form, why do you want to force me to?
 
C

Chris Morris

Mark Parnell said:
Would you expect it to do anything else?

With the obvious exception of pressing enter while focus is on the
submit button, some browsers only submit forms on enter if there is
only one (text input) field. On the other hand, some submit on
'enter' anywhere on the form.

The first behaviour is inline with HTML 2.0 specification, however I
can't find a comparable quote in the HTML 4 specification, so it's
probably undefined how browsers submit forms when enter is pressed
without a submit control focused. Or I might have missed the relevant
bit of spec.

Wanting it to not do that and only submit when focus is on the submit
button seems reasonable. Some possible solutions at:

http://www.cs.tut.fi/~jkorpela/forms/enter.html
http://ppewww.ph.gla.ac.uk/~flavell/www/formquestion.html
 
L

Luigi

Chris Morris said:
With the obvious exception of pressing enter while focus is on the
submit button, some browsers only submit forms on enter if there is
only one (text input) field. On the other hand, some submit on
'enter' anywhere on the form.

The first behaviour is inline with HTML 2.0 specification, however I
can't find a comparable quote in the HTML 4 specification, so it's
probably undefined how browsers submit forms when enter is pressed
without a submit control focused. Or I might have missed the relevant
bit of spec.

Wanting it to not do that and only submit when focus is on the submit
button seems reasonable. Some possible solutions at:

http://www.cs.tut.fi/~jkorpela/forms/enter.html
http://ppewww.ph.gla.ac.uk/~flavell/www/formquestion.html



What happens if you use a javascript to let the user send the form only if
he or she has filled all the fields of it but the user has disabled java
script on his or her browser?
 
C

Chris Morris

Luigi said:
What happens if you use a javascript to let the user send the form only if
he or she has filled all the fields of it but the user has disabled java
script on his or her browser?

Well, then _provided_ you write the javascript properly, you're no
worse off then you would have been without it there at all.

Obviously you should duplicate any checks server-side as well, and
redisplay the form appropriately if they fail.

And some of the solutions in those links don't even need Javascript -
the 'Preview/Submit' solution, for example, works entirely
server-side.
 
S

Steve Pugh

Luigi said:
What happens if you use a javascript to let the user send the form only if
he or she has filled all the fields of it but the user has disabled java
script on his or her browser?

Depending on how thoughtfully you coded things either:
(a) The form is submitted with no checking having been performed
(b) The form isn't submitted at all

(b) is just plain bad as the user might not be able to enable
JavaScript. (a) is why you need to check the form data submited on the
server even if you have client side checking via JavaScript as well.

Steve
 
A

Andrew Banks

Why duplicate them server side? Why not just do all checking server side and
then you know the environment you're working in?

Reduces the developers workload and is more economical for a business case.
 
T

Toby A Inkster

Andrew said:
Why duplicate them server side? Why not just do all checking server side and
then you know the environment you're working in?

Client-side form verification is a convenience for the end-user: it gives
them instant feedback without having to wait for the page to reload.

Hence it makes sense to duplicate.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top