SoFunction
Updated on 2025-04-10

The options of the two select multiple selection modes move each other (example code)


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/">
<html xmlns="http:///1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Unt titled document</title>
<script type="text/javascript">
function copyToList(from,to){

    var fromList=eval('[0].'+from);
    var toList=eval('[0].'+to);

    if( > 0 && [0].value == 'temp'){
            =0;
    }

    var sel=false;

    for(i = 0;i < ;i++){
        var current=[i];
        if(){
            sel=true;
            if(=='temp'){
alert('This project cannot be selected!');
                return;
            }
            txt=;
            val=;
            []=new Option(txt,val);
            [i]=null;
            i--;
        }
    }

if(!sel) alert('You haven't selected any project yet!');
}

function allSelect(){   
    var chsen=('chosen');
//If the chsen list box is 0 or the first option value is 'temp'
    if( && [0].value=="temp")
        return;

    for(var i=0;i<;i++){
            [i].selected=true;
    }

//Get data
 function getdata() {
            var List = [0].RoleList;
//Get a hidden text box object
            var roles = ("TRoleList");
            = "";
            var s = "";
            if ( != 0) {
                for (i = 0; i < ; i++) {
                    s += [i].value + ",";
                }
            }

            = s;
        }
}
</script>
</head>
<body>
<table border="0">
<form onSubmit="allSelect()">  
<tr>  
<td>  
<select name="possible" size="4" MULTIPLE width="200" style="width:200px">  
<option value="1">Guangzhou, China</option>
<option value="2">Shanghai, China</option>
<option value="3">Beijing, China</option>
<option value="4">Wuhan, China</option>
</select>  
</td>  
<td><a href="javascript:copyToList('possible','chosen')">Add to the right--><br>
<br>
</a><a href="javascript:copyToList('chosen','possible')"><--Add to the left</a></td>
<td>  
<select name="chosen"   size="4" MULTIPLE  width="200"  style="width:200px;">  
<option value="temp">Select your region from the left</option>
</select>  
</td>  
</tr>
</form>  
</table>
<input type="button"  value="submit"  onclick="allSelect()" />yle
<input type="text" style="display:none;" >
</body>
</html>