473,543 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
+ 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.v alue='Saving... '; performPrePostC hecks();">

I have tested performPrePostC hecks() - 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 performPrePostC hecks()
{
if(checkRequire dFormFields('fo rm1','headline' ,'Headline')==f alse)
{ alert("false");
return false;
}

alert("true");
return true;
}
</script>
How come that irrespective of the function performPrePostC hecks 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 128300
"Randell D." <re************ **********@and. share.com> wrote in
news:g%Wwb.4974 70$pl3.300911@p d7tw3no:
I have the following code for my submit button

<input type="submit" name="action" value="Save Article"
onClick="this.v alue='Saving... '; performPrePostC hecks();">
[snip]
How come that irrespective of the function performPrePostC hecks
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.v alue='Saving... '; performPrePostC hecks();">

To clarify Eric's correct comments, you want:
onClick="this.v alue='Saving... '; return performPrePostC hecks();"

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.4974 70$pl3.300911@p d7tw3no...

Folks

I have the following code for my submit button

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

I have tested performPrePostC hecks() - 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 performPrePostC hecks()
{
if(checkRequire dFormFields('fo rm1','headline' ,'Headline')==f alse)
{ alert("false");
return false;
}

alert("true");
return true;
}
</script>
How come that irrespective of the function performPrePostC hecks 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************ ****@spamgourme t.com> wrote in message
news:Ke******** *********@news-server.bigpond. net.au...
onClick="this.v alue='Saving... '; performPrePostC hecks();">


To clarify Eric's correct comments, you want:
onClick="this.v alue='Saving... '; return performPrePostC hecks();"

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
61408
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 programmatically issue a JavaScript statement which causes the browser to act just like the user clicked on a link in my page. And if that link has an...
3
6683
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 checkbox contain checkboxs with the same name so I can easily retrieve on my server side (java) wich checkbox are checked with a...
1
1982
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 that this is a browser common functionallity, is there anyway to deactivate this? I just want that my buttons get pressed when explicity I clik on them...
1
2556
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 save DATA". When you click "Yes" and the name form is empty. The script tell you a message, but i go to another page. ALL I WANT IS TO BLOCK IT, AND...
0
1164
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 value again. I have tried to set it to enabled = false. But when i submit the form again (other control are updated) the form is called again...
7
5293
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 Hi onchange="preview(this);return (false) ; this.form.submit()"
1
10777
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 have defined the relavant function method in the code for details) The issue is that when Icall targetForm._submit() method from the newSubmit()...
13
2857
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 to this problem
3
9457
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 example of this path would be "V:\Utilization Review\UR\ECHARTS\716632". If the appropriate folder doesn't exist at the time the user clicks this button,...
0
7355
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7356
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7697
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5892
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5285
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4900
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3395
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3395
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
648
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.