By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 1,027 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

How do I cancel a "submit"?

P: n/a

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?
May 24 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a


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.

--

Martin Honnen
http://JavaScript.FAQTs.com/
May 24 '06 #2

P: n/a
Martin Honnen wrote:


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.


And if the form is submitted using the enter key (i.e. without clicking
on either button), what should happen then?
--
Rob
Group FAQ: <URL:http://www.jibbering.com/faq/>
May 25 '06 #3

P: n/a
Martin wrote:
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

May 25 '06 #4

P: n/a
RobG wrote:
Martin Honnen wrote:
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.


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
--
A man who works with his hands is a laborer; a man who works with his
hands and his brain is a craftsman; but a man who works with his hands
and his brain and his heart is an artist.
-- Louis Nizer, lawyer (1902-1994)
May 26 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.