如何在javascript函数中设置SESSION变量调用onchange事件

时间:2015-05-28 08:27:10

标签: javascript php

我有来自数据库的下拉用户列表值。我正在调用showDiv JavaScript函数onChange用户字段事件。

在ShowDiv中我正在执行一个查询,它根据需要显示所有可用的菜单,但是如何在$ query_user_menu中使用用户的选定值(我试图存储为$ _SESSION变量,这是不起作用的)所以我可以检查现有权限并检查相应的复选框。

我的代码如下。

 <?php
 ob_start(); 
 session_start();
 require_once 'includes/DBConnection.php';
 $conn = connectDb();
 selectdb($conn);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<link rel="stylesheet" type="text/css" media="all" href="NiceForms/niceforms-default.css" />
<title></title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script >  
   function showDiv(val, divID){
      alert(val);
      document.getElementById(divID).style.display = "block";

}  

  </script>

</head>
<body onload="newbrowser()">
  <body onload="newbrowser()">
<div id="main_container">
    <form  action="delme01.php" method="post" name="bgt_crt" id="bgt_crtID">
    <table width="100%" border="0"> 
    <tr>
          <td> 
    <?PHP
               include 'TemplateMenu.php';
                ?>
   <div id="main_content">
    <select name ="user_id" id='user_idID' class="selectInput2" onchange="showDiv(this.value, 'div1')">
                            <option value="00">Select User</option>
                            <?php
                                $qry_mmenu = "select uid, user_id  from user_mst where status='A'";
                                echo "QRY=".$qry_mmenu;
                                $rs_mmenu = mysql_query($qry_mmenu);
                                $count = mysql_num_rows($rs_mmenu);
                                //echo "CNT=".$count;
                                $users = array();
                                $u = 0;
                                while($rows_mmenu = mysql_fetch_assoc($rs_mmenu)){
                                ?>
                                    <option value="<?php echo $rows_mmenu['uid'];  ?>"><?php echo $rows_mmenu['user_id']; ?> </option>
                                <?php }?>
     </select>

  <!-- DIV1 will be displayed if user select Yes Radio Button -->
<div class="row" id="div1" style="display:none">  

<table width="100%" cellpadding="2" cellspacing="2" border="1">
    <tr>
        <td width="2%"></td>
        <td width="10%">Menu Name</td>
    </tr>
<?php

    $query_user_menu = "SELECT mid FROM `user_menu_rights` WHERE `uid`= '".$_SESSION['USERID']."'";
    echo "QRY=".$query;
        $result_id = mysql_query($query_user_menu) or die(mysql_error());
    $nor = mysql_affected_rows();
    if($nor == 1)
    {
        $menu_id= implode(",", mysql_fetch_assoc($result_id));
        $id = explode(",", $menu_id);
    }

$qry_menu="SELECT a.*  FROM menu_mst a WHERE STATUS = 'A' AND a.mid NOT IN ( SELECT parent_id FROM menu_mst );";                                 
//echo "QRYBGT=".$qry_bgthd;
$rs_menu = mysql_query ($qry_menu);
while ($rows_menu = mysql_fetch_assoc($rs_menu))  {      ?>
    <tr> <td width="2%">
        <?php 
        if(in_array($rows_menu['mid'], $id)){
        ?>
            <input type="checkbox" name="menuCheckBox[]" value="<?php echo $rows_menu['mid'];?>" checked></input>
        <?php } else { ?>
        <input type="checkbox" name="menuCheckBox[]" value="<?php echo $rows_menu['mid'];?>" ></input>
        <?php } ?>
        </td>                   
       <td width="48%" align="left"><font face="Bookman Old Style" size="2" ><b><?php echo $rows_menu['menu_name'];?></b></font></td>
    </tr>
 <?php  } ?>                                            
         </table>
               </div>
  </fieldset>
 </td>
    </tr>
    </table>
         </form>
</div>
</body>
</html>

0 个答案:

没有答案