Rodrane Rodrane - 3 years ago 256
HTML Question

Onclick confirmation and then redirect

I am trying to confirm then redirect to new page.

if I delete

it confirms either way but if I keep
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

Answer Source

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';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download