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.

Source: Internet
Author: User

<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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.