<form name= "MyForm" >
<table>
<TR valign= "Top" >
<td>
<select name= "leftlist" multiple size= "6" style= "width:50px;" >
<option>a</option>
<option>b</option>
<option>c</option>
</select>
</td>
<td>
<!--call JavaScript's movelist function via the event onclick--
<input type= "button" Name= "to" value= ">>" onclick= "movelist (' leftlist ', ' rightlist ')" ><p>
<input type= "button" Name= "Backto" value= "<<" onclick= "movelist (' rightlist ', ' leftlist ')" ><p>
</td>
<td>
<select name= "rightlist" multiple size= "6" style= "width:50px;" >
<option>d</option>
<option>e</option>
<option>f</option>
</select>
</td>
</tr>
</table>
</form>
<script language= "JavaScript" >
Movelist move operation for options on two multi-select lists
From the name of the list that needs to be moved, to the move to list name
function Movelist (from,to) {
var fromlist = Document.myform.elements[from];
var fromlen = fromList.options.length;
var toList = document.myform.elements[to];
var tolen = toList.options.length;
Current option number in the "Need to move" list
var current = Fromlist.selectedindex;
Move action If there is a selection in the need to move list
while (current>-1) {
O is the current selection object in the "need to move" list
var o = fromlist.options[current];
var t = O.text;
var v = o.value;
Create a new list option based on the selected option
var optionname = new Option (t, V, false, false);
Add this option to the move to list
Tolist.options[tolen]= Optionname;
tolen++;
Clear this option from the need to move list
Fromlist.options[current]=null;
current = Fromlist.selectedindex;
}
}
</script>
Program Description:
//html DOM selectedindex Properties HTML DOM Select Object Definition and Usage the SelectedIndex property sets or returns the index number of the selected option in the drop-down list. Note: If multiple selections are allowed, only the index number of the first selected option is returned. GrammarSelectobject.selectedindex=number
There are two multiple-selection lists in the form, and users can select any item from the list on the left to add to the list on the right. Vice versa.