I am working on a web application and I would like to combine java script and php.

I am using the window.confirm() function which gives a user an option to choose either yes or no.

I am actually using this feature to end a users session so if user clicks on yes, end_session.php should be called to terminate his session and if no no action should be taken.

If there's a better java script function than window.confirm(() please tell me



8 Years
Discussion Span
Last Post by diafol

Hi you can write code in php and javascript like

<a href="javascript:confirm('<?php echo $confirm;?>
<script language="JavaScript">
function confirm(value)
    if (confirm("Are you sure you want to signout '" + value + "'"))
        window.location.href = '';

It's easy to combine java and php.
I think you understand.

Edited by mike_2000_17: Fixed formatting


window.confirm seems fine to me. What's wrong with it? The other thing you could do is create a custom (better looking) mock popup, which would basically do the same thing.
If you don't want to leave the page (window.location), you could use a very simple ajax solution to unset your session variables.

If you include the prototype.js library from prototypejs.org, it would mean creating a new js file (about 6 lines of code) and a new php file (about 1 line of code).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.