我試圖創建兩個下拉框,這樣當你從第一個選擇一個值時,第二個填充值取決於第一個值。我從about.com獲得了第一部分的代碼,但無法弄清楚如何將第二個下拉列表鏈接到網頁。2動態下拉鍊接
例如,我想將「首選項 - 選項一」鏈接到google.com,並將「首選項 - 選項二」鏈接到yahoo.com。我在哪裏包含代碼中的鏈接?
這裏是代碼:
<form name="myform">
<div align="center">
<select name="optone" size="1" onchange="setOptions(document.myform.optone.options[document.myform.optone.selectedIndex].value);">
<option selected="selected" value=" "></option>
<option value="1">First Choice</option>
<option value="2">Second Choice</option>
<option value="3">Third Choice</option>
</select>
<select name="opttwo" size="1">
<option selected="selected" value=" ">Please select one of the options above first</option>
</select>
</div>
</form>
<script type="text/javascript">
function setOptions(chosen) {
var selbox = document.myform.opttwo;
selbox.options.length = 0;
if (chosen == " ") {
selbox.options[selbox.options.length] = new Option('Please select one of the options above first',' ');
}
if (chosen == "1") {
selbox.options[selbox.options.length] = new
Option('first choice - option one','oneone');
selbox.options[selbox.options.length] = new
Option('first choice - option two','onetwo');
}
if (chosen == "2") {
selbox.options[selbox.options.length] = new
Option('second choice - option one','twoone');
selbox.options[selbox.options.length] = new
Option('second choice - option two','twotwo');
}
if (chosen == "3") {
selbox.options[selbox.options.length] = new
Option('third choice - option one','threeone');
selbox.options[selbox.options.length] = new
Option('third choice - option two','threetwo');
}
}
</script>
可能有人給我一個代碼示例?非常感謝幫助,謝謝。