Alert box OK Cancel same result

Here is the script
<script style="javascript">

function logOut()
{
    html = document.getElementsByTagName('html');
    html[0].style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)';
    if (confirm('Are you sure that you want to log out?')) { window.location.href='logout.php' } else { html[0].style.filter = ''};
}

</script>

By clicking the logout link the page is grayed out and an alert box come up asking if you want to log out, two buttons OK and Cancel, doesn't matter which one you click the result is the same you're loged out.

The question: how to fix it so when you click cancel you are actually not loged off.
LVL 28
gamebitsAsked:
Who is Participating?
 
DiscoNovaConnect With a Mentor Commented:
Ah, you have not overriden the default behaviour of the logout-link. Therefore; even when it asks if you wish to logout or not, no matter what, the link is followed anyway.

You need to change

  onclick="logOut()"

...into...

  onclick="logOut(); return false;"

...and it should work as you expect it to.
0
 
DiscoNovaCommented:
Umm... there must be something else than what you're showing us. The code seen is "correct"; it should (and does) not attempt to log you out if you click cancel (or close the shown dialog by pressing the "X" in the corner).
0
 
gamebitsAuthor Commented:
Well you can try it yourself here

http://www.newgamebits.com/login.php

user: test
password: test

after you are loged in the logout link will appear on the left side menu
0
 
gamebitsAuthor Commented:
Good job, I raised the points to the max for the extra effort, thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.