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

Thanks

Rony

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 = '';
    }
}
</script>

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

Member Avatar for diafol

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).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.