473,469 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 128288
"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: 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
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.