2 select exchange script

Just a code pattern to move options from one multiple select to another multiple select. The insert operation result is sorted by option value. Multiple items can be selected with Ctrl+Click or Shift+Click and then moved at once.

Example Source:

<html>
<head>

<script>

/*****************************************************
 * 2 selects exchange script 
 * Copyright 2001,  Virtual_max  (http://come.to/vmax)
 * Free for use for any purpose until this statement is
 * present  unchanged  in  all copies and derivatives.
 *****************************************************/

function moveOptions(from,to) {
  for(var i=0;i<from.options.length;){
     var o = from.options[i];
     if(o.selected) {
        o.selected=false;
        o = new Option(o.text,o.value);
        from.options[i] = null;
        for(var j=0; j<to.options.length;j++) {
           var more=eval(to.options[j].value+">"+o.value);
           if(more) {
             var o1=new Option(to.options[j].text,to.options[j].value)
             to.options[j] = o;
             o = o1;
           }
        }
        to.options[to.options.length]=o;         
         
     }
     else i++;
  } 
}
</script>
</head>
<body>

<form name="f">
<table border=0>

<tr><td><select name="left" MULTIPLE=true width=150  size=7 style="width:150px;">
 <option value="1">January
 <option value="2">February
 <option value="3">March
 <option value="4">April
 <option value="5">May
 <option value="6">June
 <option value="7">July
 <option value="8">August
 <option value="9">September
 <option value="10">October
 <option value="11">Novemebr
 <option value="12">December
</select>
</td><td valign="center">
 <input type="button" value=" >> " onClick="moveOptions(this.form.left,this.form.right)"><br>
 <input type="button" value=" << " onClick="moveOptions(this.form.right,this.form.left)">
</td><td>
<select name="right" MULTIPLE=true width=150 size=7 style="width:150px;">
</select>
</td>
</tr>
</table>
</form>
</body>
</html>



© 2001, Virtual_Max ( http://come.to/vmax )
Last-Modified: March 24, 2001.