Rodrane February 2016

Onclick confirmation and then redirect

I am trying to confirm then redirect to new page.

if I delete return before confirm it confirms either way but if I keep return it does not redirect to link.

<button name="payment" class="btn btn-xs-6 btn-danger btn-block" type="button"
    onclick="return confirm('are you sure you want to cancel?');window.location.href='cancel';"
    value="fav_HTML">Cancel Payment
</button>

Answers


LostMyGlasses February 2016

You need the value of confirm(), which indicates if the user confirmed or cancelled. So, instead of

return confirm('are you sure you want to cancel?'); window.location.href='cancel';

you should do

if (confirm('are you sure you want to cancel?')) window.location.href='cancel';


Durendal February 2016

r = confirm('are you sure you want to cancel?');
if (r == true) {
    window.location.href='cancel';
} else {
   //
}

Post Status

Asked in February 2016
Viewed 3,670 times
Voted 9
Answered 2 times

Search




Leave an answer