Quick Search:
 
 JavaScript: Add/Remove from Select list Jump to:  
Category: >> JavaScript >> Add/Remove from Select list  

<< lastnext >>

Snippet Name: Add/Remove from Select list

Description: Easily add or remove elements form lists.

Comment: (none)

Language: JAVASCRIPT
Highlight Mode: JAVASCRIPT
Last Modified: February 27th, 2009

<script type="text/javascript">
FUNCTION swap(index, from, to)
{
     to = document.getElementById(to);
     to.options[to.length] = NEW Option(from.options[index].text, from.options[index].value);
     from.remove(index);
}
</script>
<form>
     <table border="0" style="border-collapse: collapse" width="100%">
          <tr>
               <td valign="top">
               <select size="5" id="unselected" name="unselected" onchange="swap(this.selectedIndex, this, 'selected');">
               <option value="1 - one">1 - one</option>
               <option value="2 - two">2 - two</option>
               <option value="3 - three">3 - three</option>
               </select> </td>
               <td valign="top">
               <select size="5" id="selected" name="selected" onchange="swap(this.selectedIndex, this, 'unselected');">
               </select> </td>
          </tr>
     </table>
</form>


 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org