Move left and right to select

Source: Internet
Author: User

<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> JK: supports ethnic industries and buys less x goods as much as possible </title>
</Head>
<Body>

<Div style = "font-size: 10pt;">
Note 1: Move left and right to select <br/>
NOTE 2: Resolved issues <br/>
---- Multi-row sorting <br/>
---- Solve the problem of returning the scroll bar to zero during sorting. <br/>
<Br/>
<Br/>
Note: This page has only been tested in IE6/firefox1.5. Other browsers or other versions are not tested. <Br/>
Note -----: author JK: <a href = "mailto: jk_10000@yahoo.com.cn? Subject = about % 20 moverightorleft "> JK_10000@yahoo.com.cn </a> <br/>
<HR/>
</Div>

<Form name = FRM>

<Table>
<Tr>
<TD>
<Select name = srcselect size = 6 style = "height: 160px; width: 200px;" multiple ondblclick = "moveleftorright (document. frm. srcselect, document. frm. objselect)">
<Option value = "1"> test1 </option>
<Option value = "2"> Test2 </option>
<Option value = "3"> test3 </option>
<Option value = "4"> test4 </option>
<Option value = "5"> test5 </option>
<Option value = "6"> test6 </option>
<Option value = "7"> test7 </option>
<Option value = "8"> test8 </option>
<Option value = "9"> test9 ABCDE </option>
</SELECT>
</TD>
<TD width = "30px">
<Input align = "Left" type = button value = ">" onclick = "moveleftorrightall (document. FRM. srcselect, document. FRM. objselect) "> <br>
<Input align = "Left" type = button value = ">" onclick = "moveleftorright (document. frm. srcselect, document. frm. objselect)"> <br>
<Input align = "Left" type = button value = "<" onclick = "moveleftorright (document. frm. objselect, document. frm. srcselect)"> <br>
<Input align = "Left" type = button value = "<" onclick = "moveleftorrightall (document. frm. objselect, document. frm. srcselect)">
</TD>
<TD>
<Select name = objselect size = 6 style = "height: 160px; width: 200px;" multiple ondblclick = "moveleftorright (document. frm. objselect, document. frm. srcselect)">
<Option value = "11"> test11 </option>
<Option value = "12"> test12 </option>
<Option value = "13"> test13 </option>
<Option value = "14"> test14 </option>
<Option value = "15"> test15 </option>
<Option value = "16"> test16 </option>
</SELECT>
</TD>
<TD width = "30px">
<Input type = button value = "AA" onclick = "movetotop (document. frm. objselect)"> <br>
<Input type = button value = "A" onclick = "moveup (document. frm. objselect)"> <br>
<Input type = button value = "v" onclick = "movedown (document. frm. objselect)"> <br>
<Input type = button value = "VV" onclick = "movetobottom (document. frm. objselect)">

</TD>
</Tr>
</Table>

</Form>
</Body>

<Script language = JavaScript srccccc = "commonjs_swapoption.js">

Function moveleftorright (fromobj, toobj)
{
VaR fromobjoptions = fromobj. options;
For (VAR I = 0; I <fromobjoptions. length; I ++ ){
If (fromobjoptions [I]. Selected ){
Toobj. appendchild (fromobjoptions [I]);
I --;
}
}
}

Function moveleftorrightall (fromobj, toobj)
{
VaR fromobjoptions = fromobj. options;
If (fromobjoptions. length> 1000 ){
// If (! Confirm ("are you sure to move options? ") Return false;
}
For (VAR I = 0; I <fromobjoptions. length; I ++ ){
Fromobjoptions [0]. Selected = true;
Toobj. appendchild (fromobjoptions [I]);
I --;
}
}

Function moveup (selectobj)
{
VaR theobjoptions = selectobj. options;
For (VAR I = 1; I <theobjoptions. length; I ++ ){
If (theobjoptions [I]. Selected &&! Theobjoptions [I-1]. Selected ){
Swapoptionproperties (theobjoptions [I], theobjoptions [I-1]);
}
}
}

Function movedown (selectobj)
{
VaR theobjoptions = selectobj. options;
For (VAR I = theobjoptions. Length-2; I>-1; I --){
If (theobjoptions [I]. Selected &&! Theobjoptions [I + 1]. Selected ){
Swapoptionproperties (theobjoptions [I], theobjoptions [I + 1]);
}
}
}

Function movetotop (selectobj ){
VaR theobjoptions = selectobj. options;
VaR ooption = NULL;
For (VAR I = 0; I <theobjoptions. length; I ++ ){
If (theobjoptions [I]. Selected & ooption ){
Selectobj. insertbefore (theobjoptions [I], ooption );
}
Else if (! Ooption &&! Theobjoptions [I]. Selected ){
Ooption = theobjoptions [I];
}
}
}

Function movetobottom (selectobj ){
VaR theobjoptions = selectobj. options;
VaR ooption = NULL;
For (VAR I = theobjoptions. Length-1; I>-1; I --){
If (theobjoptions [I]. Selected ){
If (ooption ){
Ooption = selectobj. insertbefore (theobjoptions [I], ooption );
}
Else ooption = selectobj. appendchild (theobjoptions [I]);
}
}

}

Function selectalloption (selectobj ){
VaR theobjoptions = selectobj. options;
For (VAR I = 0; I <theobjoptions. length; I ++ ){
Theobjoptions [0]. Selected = true;
}
}

/* Private function */
Function swapoptionproperties (option1, option2 ){
// Option1.swapnode (option2 );
VaR tempstr = option1.value;
Option1.value = option2.value;
Option2.value = tempstr;
Tempstr = option1.text;
Option1.text = option2.text;
Option2.text = tempstr;
Tempstr = option1.selected;
Option1.selected = option2.selected;
Option2.selected = tempstr;
}
</SCRIPT>

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.