SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2005
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How can I go to a certain page after click ok in alert

    Hello,
    First of all, I am really new in Javascript.
    And I am doing most of my programming with php.

    Currently I have a problem.

    PHP Code:
    if (isExistingShowtime($db)) {
    ?>
        <script language="javascript"> 
        <!-- 
            alert("this showtime has been already in my schedule");
            
        --> 
        </script> 
    <?php 
        header
    ("location:$_SERVER[HTTP_REFERER]");

    } else {
    }

    As you see, the situation is that if this is the existed showtime, it will show alert and if the user clicks the OK of the alert, it should take him back to the calling page, but it doesn't work.

    According to my code, if it's existing showtimes, it always goes back to the calling page, not even showing the alert.

    How can I fix this problem?

    Thanks in advance.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,228
    Mentioned
    194 Post(s)
    Tagged
    2 Thread(s)

    user interaction

    Where is the value for $db coming from? When the script runs on the server, if isExistingShowtime($db) returns false it won't output the js mark-up and will go to the header redirect.

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2005
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, that is the problem.

    If isExistingShowtime($db) returns true which means there is already showtime existing, it should show alert(I hope), but it always goes to the header redirect.

    How can I fix it?

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,228
    Mentioned
    194 Post(s)
    Tagged
    2 Thread(s)

    true?

    Quote Originally Posted by lmsook
    If isExistingShowtime($db) returns true which means there is already showtime existing, it should show alert(I hope), but it always goes to the header redirect.
    Are you sure? As ot is now, if it is true, you should be getting a "headers already sent" error. Try this
    PHP Code:
    if (isExistingShowtime($db)) {
    echo $db  . " exists";
    ?>
        <script language="javascript">
        <!--
            alert("this showtime has been already in my schedule");
            
        -->
        </script>
    <?php
    //    header("location:$_SERVER[HTTP_REFERER]");

    } else {
    echo 
    $db " doesn't exist";
    }

  5. #5
    SitePoint Zealot
    Join Date
    Sep 2005
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK I did

    PHP Code:
    if (isExistingShowtime($db)) {
    echo $db  . " exists"; 

    ?>
        <script language="javascript"> 
        <!-- 
            alert("this showtime has been already in my schedule");
            
        --> 
        </script> 
    <?php 
    //    header("location:$_SERVER[HTTP_REFERER]");

    } else {
    echo 
    $db  " doesn't exists"
    }
    And I tried to add the existing one, and it showed the alert saying "this showtime has been already in my schedule", and as I clicked OK, it printed "... exists".

    The problem is that if I put it back this code
    header("location:$_SERVER[HTTP_REFERER]");
    it doesn't show any alert and just goes to that location, and it's my problem.

  6. #6
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,228
    Mentioned
    194 Post(s)
    Tagged
    2 Thread(s)

    user interaction

    Is there a way you can put the alert in the page that the redirect goes to? Or have the javascript do the redirect instead of the server-side PHP. eg.
    PHP Code:
    <script language="javascript">
        <!--
            alert("this showtime has been already in my schedule");
            document.location.href = <?php echo $_SERVER['HTTP_RREFERER']; ?>;
        -->
        </script>
    <?php
    exit; /* if you don't have to do anything thing else after this */


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •