Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
49
rated 0 times [  54] [ 5]  / answers: 1 / hits: 58667  / 13 Years ago, wed, june 1, 2011, 12:00:00

How can I copy all options of one select element to another? Please give me the easiest way, I'm allergic to looping.



Please help me. Thanks in advance!


More From » html

 Answers
17

html:



<select id=selector_a>
<option>op 1</option>
<option>op 2</option>
</select>

<select id=selector_b>
<option>op 3</option>
<option>op 4</option>
</select>


javascript:



var first = document.getElementById('selector_a');
var options = first.innerHTML;

var second = document.getElementById('selector_b');
var options = second.innerHTML + options;

second.innerHTML = options;

[#91935] Tuesday, May 31, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
leonardok

Total Points: 114
Total Questions: 94
Total Answers: 103

Location: France
Member since Thu, Oct 27, 2022
2 Years ago
;