Typical JavaScript code (11)

Source: Internet
Author: User

<Script language = "javascript1.2">
/*
This following code are designed and writen by windy_sk <windy_sk@126.com>
You can use it freely, but u must held all the copyright items!
*/
VaR mainsel = NULL;
VaR slavesel = NULL;
VaR item_org = new array ();

Function doadd (){
VaR this_sel = NULL;
For (VAR I = 0; I <mainsel. Options. length; I ++ ){
This_sel = mainsel. Options [I];
If (this_sel.selected ){
Slavesel. appendchild (this_sel );
I --;
}
}
Sort_main (slavesel );
}

Function dodel (){
VaR this_sel = NULL;
For (VAR I = 0; I <slavesel. Options. length; I ++ ){
This_sel = slavesel. Options [I];
If (this_sel.selected ){
Mainsel. appendchild (this_sel );
I --;
}
}
Sort_main (mainsel );
}

Function sort_main (the_sel ){
VaR this_sel = NULL;
For (VAR I = 0; I <item_org.length; I ++ ){
For (var j = 0; j <the_sel.options.length; j ++ ){
This_sel = the_sel.options [J];
If (this_sel.value = item_org [I] [0] & this_sel.text = item_org [I] [1]) {
The_sel.appendchild (this_sel );
}
}
}
}

Window. onload = function (){
Mainsel = select1;
Slavesel = select2;
Mainsel. ondblclick = doadd;
Slavesel. ondblclick = dodel;
VaR this_sel = NULL;
For (VAR I = 0; I <mainsel. Options. length; I ++ ){
This_sel = mainsel. Options [I];
Item_org.push (new array (this_sel.value, this_sel.text ));
}
}
</SCRIPT>

<Table width = "300" border = "0" cellspacing = "0" cellpdoadding = "0" align = "center">
<Tr>
& Lt; TD width = "45%" align = "center" & gt;
<Select id = "select1" size = "5" multiple style = "width: 100px">
<Option value = "111"> 111 </option>
<Option value = "222"> 222 </option>
<Option value = "333"> 333 </option>
<Option value = "444"> 444 </option>
<Option value = "555"> 555 </option>
<Option value = "666"> 666 </option>
<Option value = "777"> 777 </option>
<Option value = "888"> 888 </option>
<Option value = "999"> 999 </option>
</SELECT>
</TD>
& Lt; TD width = "10%" align = "center" & gt;
<Input name = "doadd" type = "button" value = ">" onclick = "doadd ()"> <br>
<Input name = "dodel" type = "button" value = "<" onclick = "dodel ()">
</TD>
& Lt; TD width = "45%" align = "center" & gt;
<Select id = "select2" size = "5" multiple style = "width: 100px">
</SELECT>
</TD>
</Tr>
</Table>

 

Related Article

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.