473,395 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to stop form submit when onClick event returns false


Folks

I have the following code for my submit button

<input type="submit" name="action" value="Save Article"
onClick="this.value='Saving...'; performPrePostChecks();">

I have tested performPrePostChecks() - Its a long script, but I have proven
its success by having an alert box echo the success with a simple true or
false message like so:

<script type="text/javascript">
function performPrePostChecks()
{
if(checkRequiredFormFields('form1','headline','Hea dline')==false)
{ alert("false");
return false;
}

alert("true");
return true;
}
</script>
How come that irrespective of the function performPrePostChecks returning
true, or false, that the form is still submitted?

Can someone point me in the right direction?

Thanks,
Randell D.
Jul 20 '05 #1
4 128281
"Randell D." <re**********************@and.share.com> wrote in
news:g%Wwb.497470$pl3.300911@pd7tw3no:
I have the following code for my submit button

<input type="submit" name="action" value="Save Article"
onClick="this.value='Saving...'; performPrePostChecks();">
[snip]
How come that irrespective of the function performPrePostChecks
returning true, or false, that the form is still submitted?


Because that's what you asked it to do. To be more specific, an action
handler is treated as if it's a function, with the return value determining
whether or not to go ahead. You don't return anything, so the default is
"yes, go ahead." Try returning the result of your checking function.

Is it possible that you're used to Perl, where a function (aka sub) by
default returns the value of the last statement executed? Javascript
doesn't use that convention; if you want to return a value, you have to do
so explicitly.
Jul 20 '05 #2
RR
> onClick="this.value='Saving...'; performPrePostChecks();">

To clarify Eric's correct comments, you want:
onClick="this.value='Saving...'; return performPrePostChecks();"

regards,
RR
Jul 20 '05 #3
put the funtion that returns fale in inte forms onsubmit handler intead of
the submit button.

Stu

"Randell D." <re**********************@and.share.com> wrote in message
news:g%Wwb.497470$pl3.300911@pd7tw3no...

Folks

I have the following code for my submit button

<input type="submit" name="action" value="Save Article"
onClick="this.value='Saving...'; performPrePostChecks();">

I have tested performPrePostChecks() - Its a long script, but I have proven its success by having an alert box echo the success with a simple true or
false message like so:

<script type="text/javascript">
function performPrePostChecks()
{
if(checkRequiredFormFields('form1','headline','Hea dline')==false)
{ alert("false");
return false;
}

alert("true");
return true;
}
</script>
How come that irrespective of the function performPrePostChecks returning
true, or false, that the form is still submitted?

Can someone point me in the right direction?

Thanks,
Randell D.

Jul 20 '05 #4

"RR" <ne****************@spamgourmet.com> wrote in message
news:Ke*****************@news-server.bigpond.net.au...
onClick="this.value='Saving...'; performPrePostChecks();">


To clarify Eric's correct comments, you want:
onClick="this.value='Saving...'; return performPrePostChecks();"

regards,
RR


Luvely Juvely... thanks to both of you - and the nice thing is, I actually
understand where I went wrong and why it should be the way you guys
suggested...

Thanks for the help,
randell d.
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Mike Gratee | last post by:
Is it possible to use JavaScript to cause the browser to click a link on a page and have the browser act exactly like the user had clicked on the link directly? In other words, I need to...
3
by: David Gonneau | last post by:
I'm getting an incredible behaviour of internet explorer. I have a generated html page with one form and many input of checkbox type. Those checkbox are grouped in 4 lists and each list of...
1
by: Fabio Cavassini | last post by:
I have implemented ""Google Suggest"" like textboxes for my application, but, when I hit enter to select the desired row of the value list, the first button of my page gets pressed. I readed...
1
by: almarc | last post by:
Problem : Stop an "Unonlaod" when then confirmation is false. Is a really good script but i have just one problem. The problem that i have is when i click on a link. The scipt ask "Do you want to...
0
by: Corinne | last post by:
Hi All, I have created a form. with radiobuttonlist. On submit the form calls itself as it reloads I want the radiobuttonlist to be displayed but i don't want anyone to be able to change the...
7
Fary4u
by: Fary4u | last post by:
Hi how to find the return value if it's wrong parameters I need to STOP form on false statement with out submitting form () <input onchange="preview(this); this.form.submit()"> I’ve tried...
1
by: gbezas | last post by:
Hi All, I have added an event handler to redirect form.submit() to a newSubmit() method that I have defined (which does some additional processing before submitting the form). Additionally I...
13
by: phpmel | last post by:
If I press the refresh button on my web form it submits the form and add the default values or whatever values that were there to the database.could anyone help me by giving me some sort of solution...
3
sueb
by: sueb | last post by:
I have a parent form (Patients) that has a subform (Accounts Subform). On my parent form is a button that opens an Explorer window pointed to a location determined by the control ChartNum. A...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.