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
https://forums.phpfreaks.com/topic/43804-solved-if-confirm-is-no-then-do-nothing/
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.

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.