如何在表单提交时捕获第二个列表



我有一个两级动态列表。它现在工作正常,问题是我无法捕获第二个列表值...我想你们可以帮助我..

这是形式

    <?php
    require 'db.php';
    ?>

    <!DOCTYPE html>
    <html>
    <head>
      <title>Selection Form</title>
     </head>
    <body>
    <form action="/display/check.php" method="get"/>
    <table>
        <tr>
        <td>Select Semester</td>
        <td>
            <select id=semesterdd onChange="change_semester()" name="sem">
                <option>
                    Select
                </option>
                    <?php
                        $result = $mysqli->query("SELECT * FROM subjects ORDER BY semester ASC") or die($mysqli->error());
                        while($row=mysqli_fetch_array($result))
                        {
                            ?>
                            <option ><?php echo $row["semester"];?></option>
                            <?php
                        }   
                    ?>
            </select>
        </td>
    </tr>
    <tr>
        <td>
            Select Subjects:  
        </td>
        <td> 
            <div id="subjectid">
                <select name='sub'>
                    <option>
                        Select
                    </option>
                </select>
            </div>
        </td>
    </tr>
    </table>
    <input type="submit" value="submit">
    </form>
    <script type="text/javascript">
        function change_semester()
        {
            var xmlhttp=new XMLHttpRequest();
            xmlhttp.open("GET","ajax3.php?semester="+document.getElementById("semesterdd").value,false);
            xmlhttp.send(null);
            alert(xmlhttp.responseText);
            document.getElementById("subjectid").innerHTML=xmlhttp.responseText;
        }
    </script>
</body>

这是 ajax 文件

<?php
require 'db.php';
$semester=$_GET["semester"];
if($semester!="")
{   
    $result=$mysqli->query("SELECT * FROM subjects WHERE semester=$semester ORDER BY subject ASC") or die($mysqli->error());
    echo "<select>";
    while($row=mysqli_fetch_array($result))
    {
                echo "<option value=>";echo $row["subject"];echo "</option>";
                //echo '<option value="'.$row['code'].'">'.$row['subject'].'</option>';

    }   
    echo "</select>";
}   
?>

这是回应..它捕获了学期选项,但为什么不是子选项?

http://127.0.0.1/display/check.php?sem=3
xmlhttp.open("GET","ajax3.php?semester="+document.getElement‌​ById("semesterdd").v‌​alue+"&sub="+document.getElement‌​ById("[subjectid]").v‌​alue,false);

将 [subjectid] 更改为您想要的任何 ID。

相关内容

最新更新