我想根据在第一个选择框中选择的内容,用适当的值填充我的第二个选择框。
这是我到目前为止所做的,但它不起作用。HTML:
<form id = "step1">
<p>
Creator:
<select name="creator" id = "creator">
<option></option>
<option name = "hello" value = "hello">Hello</option>
<option name = "abc"> oiasfn</option>
</select>
</p>
<p>
Trip Title:
<select name="title" id = "title">
<option></option>
</select>
</p>
</form>
Javascript/Jquery:
$(document).ready(function(){
updateform();
});
function updateform(){
document.getElementById("creator").onchange = populatetitle;
}
function populatetitle(){
var select = document.getElementById("creator");
if(select.options[select.selectedIndex].value = "hello"){
select.options.add(new Option('Byebye', 'Bye'));
}
}