如何将值从一个下拉列表存储到另一个下拉列表 [英] How to store value from one dropdown list to another dropdown list
问题描述
这是第一个下拉列表,
< select name =weekIdid =weekIdonchange =getSelected(value)>
< option value =Select>选择< / option>
< option value =Weekly> Weekly< / option>
< option value =Monthly> Monthly< / option>
< option value =Both> Both< / option>
< / select>
这是第二个列表,
< select id =selectedWeekname =selectedWeeksize =5multiple =multiple>
如果我在第一个下拉列表中选择每周,则必须将值存储在第二个下拉列表中。如何实现?
提前感谢!
,选项;
,selectedWeek = document.getElementById('selectedWeek')
,option;
weekId.onchange = function(){
option = document.createElement('option');
option.value = this.value;
option.text = this.options [this.selectedIndex] .text;
selectedWeek.appendChild(option);
weekId.removeChild(this.options [this.selectedIndex]);
};
在这里看到工作小提琴: http://jsfiddle.net/bKrFK/1/
最后一行事件处理程序将从weekId选择框中删除所选选项(如果不需要则删除该行)
I have 2 dropdown list, where in the first dropdown list i have some data and if I select the data it has to be stored into the second dropdown list. Here is the code :-
This is the first dropdown list,
<select name="weekId" id="weekId" onchange="getSelected(value)">
<option value="Select">Select</option>
<option value="Weekly">Weekly</option>
<option value="Monthly">Monthly</option>
<option value="Both">Both</option>
</select>
This is the second list,
<select id="selectedWeek" name="selectedWeek" size="5" multiple="multiple">
If I select Weekly in the first dropdown, the value has to get stored in the second dropdown. How do I go about implementing this?
Thanks in advance!!
var weekId = document.getElementById('weekId')
, selectedWeek = document.getElementById('selectedWeek')
, option;
weekId.onchange = function() {
option = document.createElement('option');
option.value = this.value;
option.text = this.options[this.selectedIndex].text;
selectedWeek.appendChild(option);
weekId.removeChild(this.options[this.selectedIndex]);
};
see working fiddle here: http://jsfiddle.net/bKrFK/1/
the last line in the event-handler will remove the selected option from the weekId select-box (remove that line if not needed)
这篇关于如何将值从一个下拉列表存储到另一个下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!