<script>
function add( fromCtrl , toCtrl ){
for( i=0 ;i<fromCtrl.length ;i++){
if( fromCtrl.options[i].selected == true)
{
//alert(fromCtrl.options[i].value);
for( j=0 ;j<toCtrl.length;j++)
{
if( fromCtrl.options[i].value == toCtrl.options[j].value )
{
alert("已经添加了"+fromCtrl.options[i].value);
return ;
}
}
// add item
toCtrl.options[toCtrl.length] = new Option(fromCtrl.options[i].name,fromCtrl.options[i].value);
}
}
}
function deleteItem( toCtrl ){
j=0 ;
count = toCtrl.length;
for( i=0 ;i< count ;i++){
if( toCtrl.options[i-j].selected == true){
toCtrl.remove(i-j);
j++;
}
}
}
</script>
<form name="myform">
<select name="fromsel" multiple="true" size=6>
<option name="a" value="va">a</option>
<option name="b" value="vb">b</option>
<option name="c" value="vc">c</option>
</select>
<select name="tosel" multiple="true" size=6/>
<input type="button" value="add" onclick="add(document.myform.fromsel,document.myform.tosel)"/>
<input type="button" value="delete" onclick="deleteItem(document.myform.tosel)"/>
</form>
function add( fromCtrl , toCtrl ){
for( i=0 ;i<fromCtrl.length ;i++){
if( fromCtrl.options[i].selected == true)
{
//alert(fromCtrl.options[i].value);
for( j=0 ;j<toCtrl.length;j++)
{
if( fromCtrl.options[i].value == toCtrl.options[j].value )
{
alert("已经添加了"+fromCtrl.options[i].value);
return ;
}
}
// add item
toCtrl.options[toCtrl.length] = new Option(fromCtrl.options[i].name,fromCtrl.options[i].value);
}
}
}
function deleteItem( toCtrl ){
j=0 ;
count = toCtrl.length;
for( i=0 ;i< count ;i++){
if( toCtrl.options[i-j].selected == true){
toCtrl.remove(i-j);
j++;
}
}
}
</script>
<form name="myform">
<select name="fromsel" multiple="true" size=6>
<option name="a" value="va">a</option>
<option name="b" value="vb">b</option>
<option name="c" value="vc">c</option>
</select>
<select name="tosel" multiple="true" size=6/>
<input type="button" value="add" onclick="add(document.myform.fromsel,document.myform.tosel)"/>
<input type="button" value="delete" onclick="deleteItem(document.myform.tosel)"/>
</form>