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

Php 如何在表单提交时捕获第二个列表,php,sql,forms,Php,Sql,Forms,我有一个两级动态列表。它现在运行良好的问题是,我无法捕获第二个列表值…我想你们可以帮我 这是表格 <?php require 'db.php'; ?> <!DOCTYPE html> <html> <head> <title>Selection Form</title> </head> <body> <f

我有一个两级动态列表。它现在运行良好的问题是,我无法捕获第二个列表值…我想你们可以帮我

这是表格

    <?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>
将[subjectid]更改为您想要的任何id


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

因为您没有传递它
xmlhttp.open(“GET”、“ajax3.php?sement=“+document.getElementById(“semestred”).value,false)如何修复此问题?我必须弄点东西,好像你已经为我做了一样,对你的另一个参数做同样的事情。你能帮我一下吗..我只是PHP的初学者..说实话,我从别处得到了这段代码,但现在我的整个工作都被卡住了,因为我无法阅读主题选择..我只需要传递第二个主题值..因为你没有传递它
xmlhttp.open(“GET”、“ajax3.php?sement=“+document.getElementById(“semestred”).value,false)如何修复此问题?我必须弄点东西,好像你已经为我做了一样,对你的另一个参数做同样的事情。你能帮我一下吗..我只是PHP的初学者..说实话,我从别处得到了这段代码,但现在我的整个工作都被卡住了,因为我无法阅读主题选择..我只需要传递第二个主题值..我想传递主题id,但它显示的是学期id问题..否。这是一个动态列表。第一个用户根据该学期的科目显示在第二个列表中来选择该学期。现在我需要知道用户选择的最终科目…如何做?我希望科目通过,但它显示的是学期id这是问题..否。这是一个动态列表第一个用户选择学期是基于该学期的科目显示在第二个列表中。现在我需要知道用户选择的最终科目…如何做到这一点?
<?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);