How do I cancel a "submit"?

M

Martin

I have a form with two submit buttons: <Save> and <Cancel>. When the
user clicks on <Save>, I want to execute a validate function. When he
clicks on <Cancel>, I want the form to submit without validation (I
have server side scripting that handles the two different kinds of
submits).

In the "validate" function I have "return false" in the script (if the
validation fails) but the form submits any way. How can I get this
thing to not submit on a failed validation?
 
M

Martin Honnen

Martin wrote:

In the "validate" function I have "return false" in the script (if the
validation fails) but the form submits any way. How can I get this
thing to not submit on a failed validation?

<input type="submit" name="Save" value="Save"
onclick="return validate(this.form);">
then let the validate function return true or false depending on whether
the submission should be done or cancelled.
 
R

RobG

Martin said:
Martin wrote:



<input type="submit" name="Save" value="Save"
onclick="return validate(this.form);">
then let the validate function return true or false depending on whether
the submission should be done or cancelled.

And if the form is submitted using the enter key (i.e. without clicking
on either button), what should happen then?
 
P

petermichaux

Martin said:
I have a form with two submit buttons: <Save> and <Cancel>. When the
user clicks on <Save>, I want to execute a validate function. When he
clicks on <Cancel>, I want the form to submit without validation

This sounds very shady. If the user clicks cancel they unknowingly
believe you are honest and no one will see their information.

I won't be clicking cancel anymore.

Peter
 
T

Thomas 'PointedEars' Lahn

RobG said:
And if the form is submitted using the enter key (i.e. without clicking
on either button), what should happen then?

Full ACK. I wished Martin would stop proposing this unreliable approach for
he definitely should know better, also considering that we have discussed
this ad nauseam here now, and reliable alternatives with `onsubmit' were
presented.


PointedEars
 

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,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top