Forum Moderators: open

Message Too Old, No Replies

List Box data to another List Box

how to do it in javascript

         

canadiantrip

12:24 am on Feb 5, 2008 (gmt 0)

10+ Year Member



Hi webmasters. I wonder if any of you have a javascript code that will transfer a data from a List Box to another List Box.

Thank you in advance.

eelixduppy

8:52 pm on Feb 5, 2008 (gmt 0)



Something like this would work if you wanted to move the contents from a select with ID="a" to one with ID="b". Try the following and tell me how it works:

a = document.getElementById("a");
b = document.getElementById("b");
len = a.length;
for(i = 0; i < len; i++) {
elOptNew = document.createElement('option');
elOptNew.value = a.options[i].value;
elOptNew.text = a.options[i].text;
try {
b.[url=http://www.w3schools.com/htmldom/met_select_add.asp]add[/url](elOptNew, null);
}
catch(e)
{ alert("exception caught"); }