[英]How to add options dynamically in a combobox with htmlservice and javascript
I really need you help in this, any help provided would be very well received. 在这方面,我真的需要您的帮助,我们会提供非常好的帮助。
I have 2 comboboxes 我有2个组合框
<select name="combo1" id="combo1">
<option value="April">April</option>
<option value="November">November</option>
<option value="December">December</option>
</select>
<select name="combo2" id="combo2">
</select>
And when I select an option in the first combobox, options in the second combobox should change according the selection. 当我在第一个组合框中选择一个选项时,第二个组合框中的选项应根据选择进行更改。
For example: if in the combo1 is selected "April"
, I want to show the options: "Texas","NY"
. 例如:如果在combo1中选择"April"
,我想显示选项: "Texas","NY"
。 but if "November"
is selected I want to change the states that I want to show. 但是如果选择了"November"
,我想更改我想要显示的状态。
I would really appreciate your help in this! 非常感谢您的帮助!
you should set onchange of combo1 and then check the value of it, i wrote it for you with javascript: 您应该设置combo1的onchange,然后检查它的值,我用javascript为您编写了它:
var combo1 = document.getElementById("combo1");
var combo2 = document.getElementById("combo2");
combo1.onchnage = function(){
switch(this.value){
case "April":
combo2.innerHTML = "<option value='Texas'>Texas</option><option value='NY'>NY</option>";
break;
case "November":
combo2.innerHTML = "<option value='foo'>foo</option><option value='bar'>bar</option>";
break;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.