Move the left list of JS learning notes to the right list

Source: Internet
Author: User

Functions:
1. Add the content in the drop-down box on the left to the drop-down box on the right. You can select multiple moves and remove the drop-down box objects on the right;
2. Supports moving up and down projects in the list;
3. as follows:


 
Html code
<HTML>
<HEAD>
<TITLE> select the drop-down menu </TITLE>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Meta name = "Description" CONTENT = "Power by hill">
</HEAD>
<BODY>
<P> select one or more items, click add or remove (shift or ctrl to select multiple items), or double-click the selected items to add or remove them. </P>
<Form method = "post" name = "myform">
<Table border = "0" width = "300">
<Tr>
& Lt; td width = "40%" & gt;
<Select style = "WIDTH: 100%" multiple name = "list1" size = "12" ondblclick = "moveOption (document. myform. list1, document. myform. list2)">
<Option value = "Beijing"> Beijing </option>
<Option value = "Shanghai"> Shanghai </option>
<Option value = "Shandong"> Shandong </option>
<Option value = "Anhui"> Anhui </option>
<Option value = "Chongqing"> Chongqing </option>
<Option value = "Fujian"> Fujian </option>
<Option value = "Gansu"> Gansu </option>
<Option value = "Guangdong"> Guangdong </option>
<Option value = "Guangxi"> Guangxi </option>
<Option value = "Guizhou"> Guizhou </option>
<Option value = "Hainan"> Hainan </option>
<Option value = "Hebei"> Hebei </option>
<Option value = "Heilongjiang"> Heilongjiang </option>
</Select>
</Td>
& Lt; td width = "20%" align = "center" & gt;
<Input type = "button" value = "add" onclick = "moveOption (document. myform. list1, document. myform. list2)"> <br/>
<Br/>
<Input type = "button" value = "delete" onclick = "moveOption (document. myform. list2, document. myform. list1)">
</Td>
& Lt; td width = "40%" & gt;
<Select style = "WIDTH: 100%" multiple name = "list2" size = "12" ondblclick = "moveOption (document. myform. list2, document. myform. list1)">
</Select>
</Td>
<Td>
<Button onclick = "changepos (list2,-1)" type = "button"> move up </button>
<Br/>
<Button onclick = "changepos (list2, 1)" type = "button"> move down </button>
</Td>
</Tr>
</Table>
Value: <input type = "text" name = "city" size = "40">
</Form>
<Script language = "JavaScript">
<! --
Function moveOption (e1, e2 ){
Try {
For (var I = 0; I <e1.options. length; I ++ ){
If (e1.options [I]. selected ){
Var e = e1.options [I];
E2.options. add (new Option (e. text, e. value ));
E1.remove (I );
Ii = I-1
}
}
Document. myform. city. value = getvalue (document. myform. list2 );
}
Catch (e ){}
}
Function getvalue (geto ){
Var allvalue = "";
For (var I = 0; I <geto. options. length; I ++ ){
Allvalue + = geto. options [I]. value + ",";
}
Return allvalue;
}
Function changepos (obj, index)
{
If (index =-1 ){
If (obj. selectedIndex> 0 ){
Obj. options (obj. selectedIndex). swapNode (obj. options (obj. selectedIndex-1 ))
}
}
Else if (index = 1 ){
If (obj. selectedIndex <obj. options. length-1 ){
Obj. options (obj. selectedIndex). swapNode (obj. options (obj. selectedIndex + 1 ))
}
}
}
// -->
</Script>
</BODY>
</HTML>

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.