Jump to content

[SOLVED] If confirm is NO, then do nothing.


onlyican

Recommended Posts

Hey people

 

I have a page for when the user has purchased something.

The form has 2 submit buttons.

One being "Cancel order"

Other being "Continue To Buy"

 

As you might guess, if the user Clicks "Cancel Order" I want to cancel the order.

 

Now, what happens if the user Clicks "Canel order" By accident, they actually want to purchase.

 

So I want a little bit of Javascript to check they want to cancel.

Nothing to clever, something like this.

This is what I done so far

 

//Javascript Include File
function ComfirmCancelOrder(){
var r=confirm("Are you sure you want to cancel this order?");
if(r==true){

	return true;
}else{

	return false;
}
}
function 

 

 

on the submit button for Cancel I have

<input type='submit' name='submit' value='Cancel order' onclick='ConfirmCancelOrder();' />

 

So what happens now, is the user Clicks cancel, I get a pop up saying my text, and a OK and Cancel button.

What I want is, If the user clicks OK, then the form is submitted, if the user Clicks Cancel, then nothing happens.

 

But at the moment, whatever the user clicks the form is still submitting.

 

How do I stop that form submitting if the user clicks cancel.

 

 

Link to comment
Share on other sites

Cheers for the advice, just returning the value

But I am calling the function on the onclick handler, as mentioned above.

 

<input type='submit' name='submit' value='Cancel order' onclick='ConfirmCancelOrder();' />

Or is this not what you meant.

 

Link to comment
Share on other sites

Yes, but the handler doesn't know what to do with this value!

 

Try:

 

<input type="submit" name="submit" value="Cancel order" onclick="return ConfirmCancelOrder();" />

 

Much like you would for a "fake" href onclick or a form onsubmit validation.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.