473,490 Members | 2,489 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How do I cancel a "submit"?


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
4 15210


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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
12360
by: lsarg | last post by:
i've been trying forever to figure out a way to use a regular text link in place of a submit button at the bottom of this. can't get it. i'm just starting to learn php, so i'm stuck. any help at...
7
5273
by: NotGiven | last post by:
I changed my POST to GET and find appended to the url, the above string. Why and what can I do to NOT have them appended? Thanks.
3
7704
by: Pete Wilson | last post by:
How can I highlight the <input type="submit"> object that I want to highlight? 1. In my form, the user enters his ID. He sees two submit "buttons," left labeled Cancel, the right labeled Signup....
2
8095
by: Laermans_k | last post by:
Hi, Does anyone have a solution to use the <input type="file" id="filechooser"> and the <input type="submit" id="submitbutton"> in 1 button click? I've already tried to create a javascript...
3
10127
by: Adam | last post by:
Hey guys, I've decided to stop banging my head against the wall and just ask you guys for the answer. I can't seem to find it. I have a form in which I have multiple submit buttons; only, I'm...
2
1732
by: Sanjeeb Sarangi | last post by:
I have got a couple of Serverside Button Controls in a page. Each button performs different actions, e.g. Button1 performs Submit, Button2 performs Cancel etc. Now, I want the default button mapped...
4
16234
by: dschruth | last post by:
Hello. Can anybody solve this problem? I am using a server-side language (PERL) to *try* to POST data to a HTTPS login script that doesn't have a standard "submit" button. The form appears...
9
2306
by: Alexandra | last post by:
Not sure why none of these permutations are working. I appreciate a second set of eyes! .... <form id="form1" name="form1" > .... <input name="Submit1" type="submit" tabindex="10"...
14
75429
by: white lightning | last post by:
How to have <select onchange="this.form.submit()"and also a Submit button on one form? I have something like this: <form action="<?php $_SERVER; ?>" method="post"...
0
7112
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6974
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7146
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7183
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
4573
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3074
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
628
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
277
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.