Jump to content

ALERT


jwk811

Recommended Posts

When you create the confirmation dialog box using the confirm function you store it in a variable:
[code]myConf = confirm('my confirmation message here');[/code]

Now the variable myConf will hold the value of true if the user clicks the OK Button, or false if the user clicks the cancel/close button. So to see what button they chose you use a if statement like so:
[code]if(myConf) {
    // TRUE - OK Button
} else {
  // FALSE - Cancel/Close Button
}[/code]
Link to comment
Share on other sites

You'll need to add that code into a function like so:
[code]function confirmLogout()
{
    confirmLogout = confirm('Are you sure you want to logout?');

    if(confirmLogout) {
return true;
    } else {
return false;
    }
}[/code]

Then for your log out link, it'll be like this:
[code]<a href="logout.php" onclick="return confirmLogout()">Logout</a>[/code]

Now what it will do is if you click the link it'll wait until your press the OK or Cancel button on the confirmation dialogue box that will popup. If you press the Ok button it will then continue on to logout.php or whatever the destination is for the link. If you click the Cancel button or close the confirmation dialogue box it will do nothing and keep you on the same page.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.