title: Get a listbox's selected items in javascript
body: <p>I have two listboxes in asp.net. On the click of a button I want to load a list box with the elements of the selected items in the other box. The problem is that this has to be done on the client side because when the button is clicked I don't allow it to submit. I want to call a javascript function onselectedindexchange but that is server side. any ideas? Should i be more clear?</p>
  
  <p><strong><em>Solution</em></strong><br></p>
  
  <pre><code>enter code here
  function Updatelist() {
      var sel = document.getElementById('&lt;%=ListBox1.ClientID%&gt;')
      var lst2 = document.getElementById('&lt;%=ListBox2.ClientId %&gt;')
      var listLength = sel.options.length;
      var list2length = lst2.options.length;
      for (var i = 0; i &lt; listLength; i++) {
          if (sel.options[i].selected) {
              //lst2.options.add(sel.options[i].text);
              lst2.options[list2length] = new Option(sel.options[i].text);
              list2length++;
          }
      }
  }
  </code></pre>