JS Select implements the left and right values. html

Source: Internet
Author: User

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title>untitled document</title>


<script language= "JavaScript" >
function AddItem (objform)
{
var valueary=new Array ();
var textary=new Array ();
var leftelement=objform.elements["left"];
var rightelement=objform.elements["right"];
var count=0;
var I,j,k,flag;
for (i=0;i<leftelement.options.length;i++)
{
if (leftelement.options[i].selected)
{valueary[count]=leftelement.options[i].value;
Textary[count]=leftelement.options[i].text;
count++;
}
}
var count1=rightelement.options.length;
count1=count1>0?count1:0;
for (j=0;j<count;j++)
{
Flag=false;
for (k=0;k<count1;k++)
{
if (Rightelement.options[k].text==textary[j])
Flag=true;
}
if (!flag)
{
Rightelement.options[count1]=new Option (Textary[j],valueary[j]);
count1++;
}
}
}
function Subitem (objform)
{
var i;
var objelement=objform.elements["right"];
for (i=objelement.options.length-1;i>=0;i--)
{
if (objelement.options[i].selected)
Objelement.options[i]=null;
}
}
function Addallitem (objform)
{
var i;
var leftelement=objform.elements["left"];
for (i=0;i<leftelement.options.length;i++)
{
Leftelement.options[i].selected=true;
}
AddItem (Objform);
}
function Suballitem (objform)
{
var i;
var rightelement=objform.elements["right"];
for (i=0;i<rightelement.options.length;i++)
Rightelement.options[i].selected=true;
Subitem (Objform);
}
</script>

<body>

<table width= "cellpadding=" 0 "cellspacing=" 0 "border=" 0 ">
<form>
<tr>
<td "Width=" rowspan= "4",
<select name= "left" style= "width:80px;height:100px;" Multiple>
<option >ITEM1</option>
<option>ITEM2</option>
<option>ITEM3</option>
< Option>item4</option>
<option>ITEM5</option>
<option>ITEM6</option>
</select></td>
<td width= "height=" align= "center";
<input type= "button" value= " >> "onclick=" AddItem (This.form);
</td>
<td width= "rowspan=" 4 "align=" right ">
<select name=" right "style=" width:80px ; height:100px; "Multiple>
</select>
</td>
</tr>

<tr>
<TD width= "align=" center "><input type=" button "value=" << "onclick=" Subitem (this.form) "></ Td>
</tr>
<tr>
<TD width= "align=" center "><input type=" button "value=" all>> "onclick=" Addallitem (this.form) "> </td>
</tr>
<tr>
<TD width= "align=" center "><input type=" button "value=" <<all "onclick=" Suballitem (this.form) "> </td>
</tr>
</form>
</tr>
</table>
</body>

JS Select implements the left and right values. 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.