473,597 Members | 2,413 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 128324
"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
61419
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 onClick JS event defined, I'd want that onClick event to execute too, exactly the same as if the user...
3
6689
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 request.getParameterValues(). (Each checkbox has a value corresponding to the id of the row) Anyway that's not on the...
1
1987
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 Regards Fabio Cavassini
1
2562
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 STAY IN THE SAME PAGE WITHOUT RELOADING. LIKE WHEN YOU CLICK SUBMIT. Can some one help me ? Is a...
0
1170
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 butthis time the radiobuttonlist has lost its values.
7
5299
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
10795
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() function the page I get an 'Object doesn't support this property or method' error I am using IE...
13
2863
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
9468
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, it creates it and then opens the window. On the subform is a control that contains an account...
0
8263
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8379
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8254
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6677
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5421
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3917
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2393
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 we have to send another system
1
1492
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1226
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.