stebo
stebo

Reputation: 3

Javascript form submit confirmation with redirect if true

This javascript works to confirm the form before it's submitted, however i don't know what to do to add a redirect link if they confirm true, or if they confirm false:

Javascript

<script>
function cancelalert(){
return confirm("By clicking OK you are submitting the form.");
}
</script>

HTML

onclick="return cancelalert()"

Upvotes: 0

Views: 977

Answers (1)

Oded
Oded

Reputation: 498952

Instead of returning the result of confirm directly, put it in a variable and act accordingly:

var confirmed = confirm("By clicking OK you are submitting the form.");

if(confirmed)
{
  return true; // will sumbit the form. Do a redirect on the server side
}

// not confirmed. Show an alert or something

Upvotes: 1

Related Questions