PDA

View Full Version : Confirmation Help Please


richard_r
06-27-2002, 04:54 AM
Okay, I am going to try and make this as simple, and understandable as possible...

I have a page that when you open it, a confirmation appears(voila!). What I would like to know how to do is, how do you allow the person to continue to the page when he clicks OK. When he clicks Cancel, how do you send him to an alert that says Have a nice day!, then send him to the last page he was at..

here is what I have for the code (not much, so that's why I asked you people.. )

<script language="JavaScript">
var enter=window.confirm("Enter? \n\n Click okay to enter. \n Click cancel to return to the previous page. \n\n Either way, you were given a choice.");
// alert(" Welcome to ... "); is for the OK
// alert(" Have a nice day! "); is for the CANCEL

// I have no idea what goes in here for the OK alert to
// redirection, and CANCEL alert to previous page
// I don't know if I should use onClicks, or some other form of JS
// I hope that somebody does...

</script>

x_goose_x
06-27-2002, 05:41 AM
<script>
con = window.confirm("Do you agree?");
if (con==false) {
alert(" Have a nice day! ");
opener.history.go(-1)
}
</script>

lpok
06-27-2002, 05:43 AM
When the user clicks ok, the confirm function returns the boolean true.

When the user clicks cance, it returns the boolean false;

So you can do something like this:


var enter = comfirm("blah, click something");
if (enter)
{
alert("you clicked ok");
// other code you want executed
}
else
{
alert("you clicked cancel");
// other code you want executed
}

richard_r
06-27-2002, 07:09 AM
that code works fine.. although I did have to change a few things around..

comfirm.. to confirm but nothing majorly drastic


Thanks!
Richard