php页面中有一个二级联动,选择他们后其他的表单数据被清空怎么办呢?

解决方案 »

  1.   

    用js的getelementById可以解决
      

  2.   

    <HTML><HEAD>
    <META http-equiv=Content-Type content="text/html; charset=gb2312">
    <LINK href="css/admin.css" type="text/css" rel="stylesheet">
    </HEAD>
    <script language="javascript">
    function selectdepartment(x){
        if(x!="请选择"){
           window.location.href='student.php?pid='+x;
      } 
       } 
       function selectmajor(x){
        if(x!="请选择") {
           window.location.href='student.php?cid='+x+"&pid="+form1.select1.value;
      } 
       }
    </script>
    <BODY>
    <TABLE cellSpacing="0" cellPadding="0" width="100%" align="center" border=0>
    <form name="form1" method="post" action="addstudent.php">
      <TR height=28>
        <TD background=images/title_bg1.jpg>当前位置: </TD></TR>
     <TR>
        <TD bgColor=#b1ceef height=1></TD></TR>
      <TR height=20>
        <TD background=images/shadow_bg.jpg></TD></TR></TABLE>
    <table align="center" border="1">
    <tr>
    <tr>
    <td>学号<input type="text" name="PostID"  /></td>
    <td>姓名<input type="text" name="name"  /></td>
    <td>籍贯<input type="text" name="nation"  /></td>
    </tr>
    <tr>
    <td>民族<input type="text" name="nation"  /></td>
    <td>性别:男<input name="sex" type="radio" checked="checked" value="男" >女<input name="sex" type="radio"   value="女" ></td>
    <td>密码<input type="text" name="password"  /></td>
    </tr>
    <td>入学年份<input type="text" name="year"  />
    <td>学院<select name="select1" onChange="selectdepartment(this.value);">
    <option  value="请选择" selected="selected"> 请选择</option>
    <?php for($i = 0; $i < $num_department; $i++)
    {
    $row1 = $result1->fetch_assoc();

    ?>
    <option value=<?php echo $row1[ID]; ?>
    <?php
       if($_SESSION["pid"]!="") {
          if($_SESSION["pid"]==$row1[ID]){
           echo "selected=\"selected\""; 
         }
        }
    ?> > <?php echo $row1[name];?></option>
    }
    <?php
      
    }
    ?>
    </select></td>
    <td>选择班级<select name="select2" onChange="selectmajor(this.value);" >
    <option  value="请选择" selected="selected"> 请选择</option>
    <?php if($_GET[pid]!="") { ?>
    <?php 
       $query5="select * from major where departmentID='".$_GET[pid]."'"; 
       $result5 = $db ->query($query5);
    $num_major = $result5->num_rows;
    ?>
    <?php for($i = 0; $i < $num_major; $i++)
    {
    $row5 = $result5->fetch_assoc();

    ?>
    <option value=<?php echo $row5[ID]; ?>
    <?php
       if($_SESSION["cid"]!="") {
          if($_SESSION["cid"]==$row5[ID]){
           echo "selected=\"selected\""; 
         }
        }
    ?>> <?php echo $row5[name];?></option>
    }
    <?php
      
    }}
    ?>
    </select></td>
    </tr>
    <tr>
    <td><input type="submit" value="添加" /></td>
    <td><input type="reset" value="重置" /></td>
    </tr>
    </table>
      

  3.   

    onchange()事件发生以后直接跳转到别的页面了,其它表单内容当然清空了这两个下拉框控件也根本没有实现联动。