
July 20th, 2005, 01:08 PM
| | | 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. | 
July 20th, 2005, 01:08 PM
| | | Re: How to stop form submit when onClick event returns false
"Randell D." <reply.to.news.group.only@and.share.com> wrote in
news:g%Wwb.497470$pl3.300911@pd7tw3no:
[color=blue]
> I have the following code for my submit button
>
> <input type="submit" name="action" value="Save Article"
> onClick="this.value='Saving...'; performPrePostChecks();">[/color]
[snip]
[color=blue]
> How come that irrespective of the function performPrePostChecks
> returning true, or false, that the form is still submitted?[/color]
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. | 
July 20th, 2005, 01:08 PM
| | | Re: How to stop form submit when onClick event returns false
> onClick="this.value='Saving...'; performPrePostChecks();">
To clarify Eric's correct comments, you want:
onClick="this.value='Saving...'; return performPrePostChecks();"
regards,
RR | 
July 20th, 2005, 01:08 PM
| | | Re: How to stop form submit when onClick event returns false
put the funtion that returns fale in inte forms onsubmit handler intead of
the submit button.
Stu
"Randell D." <reply.to.news.group.only@and.share.com> wrote in message
news:g%Wwb.497470$pl3.300911@pd7tw3no...[color=blue]
>
> 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[/color]
proven[color=blue]
> 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.
>
>[/color] | 
July 20th, 2005, 01:09 PM
| | | Re: How to stop form submit when onClick event returns false
"RR" <newspaper.20.broom@spamgourmet.com> wrote in message
news:KeYwb.27578$aT.4901@news-server.bigpond.net.au...[color=blue][color=green]
> > onClick="this.value='Saving...'; performPrePostChecks();">[/color]
>
> To clarify Eric's correct comments, you want:
> onClick="this.value='Saving...'; return performPrePostChecks();"
>
> regards,
> RR
>
>[/color]
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. |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over network members.
|