Listbox Move Left / Right Options

by GOKILAVANI 2014-05-26 09:49:19

This javascript function lets you move selected OPTIONS between two SELECT boxes. Check below reference for details.
 
function listbox_moveacross(sourceID, destID) {
    var src = document.getElementById(sourceID);
    var dest = document.getElementById(destID);
  
    for(var count=0; count < src.options.length; count++) {
  
        if(src.options[count].selected == true) {
                var option = src.options[count];
  
                var newOption = document.createElement("option");
                newOption.value = option.value;
                newOption.text = option.text;
                newOption.selected = true;
                try {
                         dest.add(newOption, null); //Standard
                         src.remove(count, null);
                 }catch(error) {
                         dest.add(newOption); // IE only
                         src.remove(count);
                 }
                count--;
        }
    }
}
//..
//..
 
listbox_moveacross('countryList', 'selectedCountryList');




Tagged in:

915
like
0
dislike
0
mail
flag

You must LOGIN to add comments