Some simple problem for PHP & JS, I can call the function. why??

Discussion in 'Programming' started by tingwang, Jun 4, 2010.

  1. #1
    I wanna if user click "2nd page" and then a message pop up.
    But why the function cant work??
    If someone know why pls tell me!! T__T
    This is my code:

    <?PHP
    require_once('conn.php');
    ?>
    <?php
    //session_start();
    //echo $_SESSION['p_level'];
    ?>
    <script language="JavaScript">

    function CheckLevel()
    {
    var p_level = "<?php $_SESSION['p_level']?>";

    if(p_level == 1)
    {
    alert("Sorry You cannot access!");
    }
    else
    {
    return true;
    }
    }
    </script>
    <body>

    <table width="784" border="1">
    <tr>
    <td align="center" scope="row"><a href="1st_Page.php">1st Page</a></td>
    <td align="center"><a href="2nd_Page.php" onclick="return CheckLevel();">2nd Page</a></td>
    <td align="center"><a href="3rd_Page.php">3rd Page</a></td>
    </tr>

    </table>

    </body>
     
    tingwang, Jun 4, 2010 IP
  2. nimonogi

    nimonogi Active Member

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    80
    #2
    Try this:
    
    <td align="center"><a href="#" onclick="document.location.href='2nd_Page.php'; CheckLevel();">2nd Page</a></td>
    
    Code (markup):
     
    nimonogi, Jun 4, 2010 IP