auto form submit on ENTER key

P

ppcguy

i've got a login page with name and password and
would like the form to be submitted with the
user presses on either of the two input fields.

it works if i do this

<INPUT TYPE="Submit" NAME="Submit" VALUE="Login">

but does not for this:

<INPUT TYPE="Button" NAME="Submit" VALUE="Login"
onclick="onSaveClicked(this)">

help!!!
 
D

David Dorward

ppcguy said:
it works if i do this
<INPUT TYPE="Submit" NAME="Submit" VALUE="Login">
but does not for this:
<INPUT TYPE="Button" NAME="Submit" VALUE="Login"
onclick="onSaveClicked(this)">

So don't do that! (Depending on JavaScript is a poor idea anyway)
 
R

Roy Schestowitz

ppcguy said:
i've got a login page with name and password and
would like the form to be submitted with the
user presses on either of the two input fields.

it works if i do this

<INPUT TYPE="Submit" NAME="Submit" VALUE="Login">

but does not for this:

<INPUT TYPE="Button" NAME="Submit" VALUE="Login"
onclick="onSaveClicked(this)">

help!!!

Why would you ever want to use the latter if the former works? The simpler
form gives you the correct behaviour by default...

Roy
 
S

Safalra

Roy said:
Why would you ever want to use the latter if the former works? The simpler
form gives you the correct behaviour by default...

I presume the the original poster wants to do something with Javascript
before submitting the form. If this is input validation (the most
common use of Javascript in forms), it's a really bad idea: never rely
on client-side validation - always perform it on the server side for
security.
 
B

Benjamin Niemann

Safalra said:
I presume the the original poster wants to do something with Javascript
before submitting the form. If this is input validation (the most
common use of Javascript in forms), it's a really bad idea: never rely
on client-side validation - always perform it on the server side for
security.

Sure, but this does not imply that (unobstrusive) client-side validation
must not be done. If it degrades well on non-JS user-agent it can provide a
better usability for the website, saving the user from extra server
roundtrips. But you'll have to implement the validation twice (client-side
JavaScript, server-side whatever) and keep these implementations in sync.

What the OP should do, to do form validation:

<INPUT TYPE="Submit" NAME="Submit" VALUE="Login" onclick="return
validateForm()">

where validateForm() returns 'false', if validation failed.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top