如何从依赖下拉列表获取值到JavaScript并将其解析到另一个PHP页面


how to get value from dependant drop down list to javascript and parsing it to another php page?

我做了一个 2 级依赖的下拉列表,工作正常,但我不知道如何使用 javascript 获取 2 级值。这是我正在使用的代码。

下拉列表.html:

<script type="text/javascript" src="../js/dropdown_list.js"></script>
<select class="level" id="level1" onChange="get_level2(this.value)">
    <option selected="selected" value="0">--Choose One--</option>
<?php
$sql_get = mysql_query ("SELECT * FROM ajax_table WHERE pid=0");
    while($row_get = mysql_fetch_array($sql_get))
    {
        echo "<option value='".$row_get['id']."'>".$row_get['category']."</option>";
    }
    ?>
    </select>
    <span id="level2"></span>

因为家属工作得很好..所以我想我可以跳过get_level2 ()函数和另一个 php 文件来处理第二级下拉菜单。.

这是我尝试在单击按钮时从下拉列表中获取值的代码。

dropdown_list.js :

function cekForm() {
//the getValue1 work fine but I can't make getValue2 work..
//how to get value from 2nd level drop down list with getValue2??
var value1 = document.getElementById("level1");
var getValue1 = value1.options[value1.selectedIndex].value;
var value2 = document.getElementById("level2");
var getValue2 = value2.options[value2.selectedIndex].value;
if (getValue1 == 0){
alert("Please Choose One");
}
if (getValue1 != 0){
//where I want to pass the dropdown value to post_value.php
window.location= "post_value.php";
}
}

如何获取第二级下拉列表的值?以及如何将值传递给post_value.php??

请帮帮我...

更新:

以下是来自火狐视图页面源代码的代码:

//this is <head> part
  <link href="../css/val.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/jquery-2.0.3.min.js"></script>
<script type="text/javascript" src="../js/dropdown_list.js"></script>
//end of </head>
//<body> part
<div class="form-div">
    <form id="form_level" name="form_level" style="padding-top:0px;">
    <div class="form-row" style="padding-top:0px;">
    <h3>Choose Drop Down :</h3>
    <select class="level" id="level1" onChange="get_level2(this.value)" style="position:relative; top:-40px; left:150px;">
    <option selected="selected" value="0">--Choose One--</option>
    <option value='1'>BAA</option><option value='2'>BAK</option><option value='3'>BAUK</option></select>
    <span id="level2"></span>
    </div>

      <div class="form-row" style="position:relative; top:100px; left:305px;">
      <input class="submit" value="Send" type="button" onClick="cekForm()">
      </div>
      <br /><br />
    </form>
</div>

通过 url 使用 get 方法传递值

<script>
function cekForm() {
    var getValue1 = document.getElementById("level1").value;
    var getValue2 = document.getElementById("level2").getElementsByTagName("select")[0].value;
    if (getValue1.length==0){
        alert("Please Choose One");
        return;
    }
    if (getValue1.length>0){
        window.location= "post_value.php?level1="+getValue1+"&level2="+getValue2;
    }
}
</script>

并在PHP文件中接收它

post_value.php

<?php
$level1 = $_GET["level1"];
$level2 = $_GET["level2"];
?>