Confirm Box Problems

I

Iain Adams

Hey I have a confirm box that is invoked when the submit button is
pressed.

i.e onClick="ConfirmationBox()"

then I have a javascript function like so

function ConfirmationBox()
{

var confirmBox = confirm("Do you want to proceed?");

if(confirmBox)
{
//proceed to form action page
}
else
{
//dont do anything
}

}

Okay so when I click the OK button on the confirmation box i want it to
proceed. If the cancel button is pressed I dont want it to do anything.
Basically if cancel is pressed the box disappears and the page that the
box was invoked from remains, unchanged. How do i do this?? I have
tried returning true/false etc.
 
T

tutsamewasa

Hi,

Make you submit button as normal button and call function
"ConfirmationBox" on clieck of the button.

within this function when user clicks ok

do like

document.formname.submit();

Hope this helps.
Please feel free if you have further queires.


Good Luck

Hemendra Singh Shaktawat

Mindfire Solutions
www.mindfiresolutions.com
 
M

Matt Kruse

Iain said:
Hey I have a confirm box that is invoked when the submit button is
pressed.

Instead, use the onsubmit handler of the form tag:

<form onsubmit="return confirm('Do you want to proceed?')" ...>

That's it!

You can break it out into a separate function if you wish.
 
R

Randy Webb

tutsamewasa said the following on 7/21/2006 8:25 AM:
Hi,

Make you submit button as normal button and call function
"ConfirmationBox" on clieck of the button.

No, don't do that.
within this function when user clicks ok

do like

document.formname.submit();

Again, don't do that.

<form ...... onsubmit="return ConfirmationBox()">

And then have the function return true or false.
Hope this helps.

It did more harm than good.
 
T

tutsamewasa

Hi Randy Webb,

"It did more harm than good."

Could you please tell what is the problem with that solutions??

Will help me learning if I am wrong.

Thanks

Hemendra Singh
 
R

Randy Webb

tutsamewasa said the following on 7/22/2006 5:39 AM:
Hi Randy Webb,

"It did more harm than good."

Yes, it did.
Could you please tell what is the problem with that solutions??
Will help me learning if I am wrong.

Using a normal button and then using JS to submit a form is a bad
solution because it introduces a dependency on JS that doesn't have to
be there. If JS is disabled or a script error occurs in the page
anywhere then you can't submit the form. Using the onsubmit handler of
the form allows the form to "degrade gracefully" in the event of an
error (JS error) or if JS is disabled.

<form onsubmit="return ConfirmationBox()">

function ConfirmationBox(){
var satisfaction = false;
//do some validation here. Whether it is confirm boxes
//prompts, form field validation. If you are satisfied
//with the results, you return true and the form gets
//submitted. If you aren't satisfied, you return false
//and the form doesn't get submitted.
return satisfaction;
}

Please don't top-post to comp.lang.javascript
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,592
Members
45,103
Latest member
VinaykumarnNevatia
Top