Search code examples
asp.netjavascriptlistboxlistbox-control

Moving items in Dual Listboxes


How can I move items from one list box control to another listbox control using JavaScript in ASP.NET?


Solution

  • This code assumes that you have an anchor or that will trigger to movement when it is clicked:

    document.getElementById('moveTrigger').onclick = function() {
    
        var listTwo = document.getElementById('secondList');
        var options = document.getElementById('firstList').getElementsByTagName('option');
    
        while(options.length != 0) {
            listTwo.appendChild(options[0]);
        }
    
     }