我制作了一个依赖于 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?
请帮我...
更新 :
这是来自Firefox视图页面源的代码:
//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>