Jump to content

When Button Clicked ask to save or cancel, if save then redirect


evr72

Recommended Posts

Hello, I am new at Javascript and trying to make this work. I have a button that I have called "Back To Main Page"I have the followin script

 onclick="if (confirm('Would You Like To Save Your Work?'))submit(); return false;" 

This works and it asks the user if he/she would like to save ther work if they click ok it saves if cancel noting happens up to this point is ok, but I would like to redirect the user to another page if the user clicks ok I have tried a few things but nothing seems to work. any help is much appreciated. thanks!!

Link to comment
Share on other sites

You can do as follows to acheive what you want.

function submit() { //submit watever you want to submit//and if submit is successfull return true//else return false} function onBackClicked() {   if(confirm("Would you like to save your work?")) {if(submit()) //when submit is successfull redirectwindow.location.url = "desired url of home page";  }elsereturn false;}  onclick="onBackClicked();"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...