Forum Moderators: open
for (var i = 0; i <= varFromBox.options.length; i++) {
msg = msg + i + "\n";
var newOption = new Option(); // Create a new instance of ListItem
newOption.text = varFromBox.options[varFromBox.options.selectedIndex].text;
newOption.value = varFromBox.options[varFromBox.options.selectedIndex].value;
varToBox.options[varToBox.length] = newOption; //Append the item in Target Listbox
varFromBox.remove(varFromBox.options.selectedIndex); //Remove the item from Source Listbox
} //for
}//test
something is wrong with that function. What is it? Thanks,
if (varFromBox.length < 1) {
should be
if (varFromBox.options.length < 1) {
Also:
for (var i = 0; i <= varFromBox.options.length; i++) {
should be
for (var i = 0; i < varFromBox.options.length; i++) {
And then inside that for loop:
if (varFromBox.options[i].selected) {
msg = msg + i + "\n";
var newOption = new Option(); // Create a new instance of ListItem
newOption.text = varFromBox.options[i].text;
newOption.value = varFromBox.options[i].value;
varToBox.options[varToBox.options.length] = newOption; //Append the item in Target Listbox
varFromBox.remove(i); //Remove the item from Source Listbox
}