Category: >> JavaScript >> Add/Remove from Select list Bookmark and Share

<< lastnext >>

Snippet Name: Add/Remove from Select list

Description: Easily add or remove elements form lists.

Comment: (none)

Author: CoderZone
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);
     <table border="0" style="border-collapse: collapse" width="100%">
               <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>
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© | users online: 10