我有三個下拉菜單。基於在第一個下拉列表中選擇的選項,我使用javascript填充第二個下拉列表。用查詢結果填充第三個下拉列表
第一個下拉
<select id="continent" onchange="secondMenu(this,'country')" >
<option value="1">Asia</option>
<option value="2">Europe</option
</select>
第二個下拉
<select id="country" >
</select>
第三下拉
<select id="population" >
</select>
我的腳本
<script>
function secondMenu(ddl1,ddl2){
var as=new Array('Japan','China');
var eu=new Array('Germany','France');
switch (ddl1.value) {
case 1:
document.getElementById(ddl2).options.length = 0;
for (i = 0; i < as.length; i++) {
createOption(document.getElementById(ddl2), as[i], as[i]);
}
break;
case 2:
document.getElementById(ddl2).options.length = 0;
for (i = 0; i < eu.length; i++) {
createOption(document.getElementById(ddl2), eu[i], eu[i]);
}
break;
}
function createOption(ddl, text, value) {
var opt = document.createElement('option');
opt.value = value;
opt.text = text;
ddl.options.add(opt);
}
</script>
現在基於在第二個下拉列表中選擇的選項,我想運行一個mysql查詢並填充第三個下拉列表。有關如何填充第三個下拉列表的任何幫助。
您需要在[AJAX](http://en.wikipedia.org/wiki/Ajax_(編程))中查找爲了從服務器請求額外的(和有條件的)數據 – juco 2013-03-06 10:39:09