CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   Confirmation box help :( (http://www.codingforums.com/showthread.php?t=284367)

lanx2cool 12-18-2012 07:53 PM

Confirmation box help :(
 
hello guys im confuse, what is the error in my code

i want to create a dialog box that if the user click true, the user will be directed to an another page
but if false it will stay on the current page

here is my code:

Code:

<script type="text/javascript">
function show_confirm()
{
       
        var s= confirm("Are you sure?")
        if (s==true)
                {
                        <? header("Location: sad52/enrollment.php"); ?>
                        }
        else
                {
                        <? header("Location: sad52/studentpage.php"); ?>
                        }
       
        }
</script>
<br /><input type="button" value="Enroll" onClick="show_confirm()" />
</form>


devnull69 12-18-2012 07:57 PM

You'll have to understand that your PHP code will already be finished when Javascript is running. So if you put PHP code into your Javascript conditional, it won't do anything at run time because it will already have been evaluated and executed at page creation time.

You can do the redirection with Javascript only, though
Code:

function show_confirm()
{
       
        var s= confirm("Are you sure?")
        if (s==true)
                {
                        window.location.href = "sad52/enrollment.php";
                }
       
}


lanx2cool 12-18-2012 08:03 PM

Quote:

Originally Posted by devnull69 (Post 1300864)
You'll have to understand that your PHP code will already be finished when Javascript is running. So if you put PHP code into your Javascript conditional, it won't do anything at run time because it will already have been evaluated and executed at page creation time.

You can do the redirection with Javascript only, though
Code:

function show_confirm()
{
       
        var s= confirm("Are you sure?")
        if (s==true)
                {
                        window.location.href = "sad52/enrollment.php";
                }
       
}


Thank you it fixed my problem, and im sorry im just a newbie :)

felgall 12-18-2012 08:51 PM

You also need to get rid of the confirm() call - it only continues to exist so it can be used for debugging scripts - in most browsers it will display an extra checkbox to either turn off all subsequent alert/confirm/prompt dialogs when the second such dialog is displayed. In at least one browser it always displays an extra checkbox allowing JavaScript to be turned off completely for the current web page every time it displays.


All times are GMT +1. The time now is 06:46 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.