The two options for the select multiselect mode move the of sample code to each other
- 2020-03-30 01:20:34
- OfStack
As follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Headless document </title>
<script type="text/javascript">
function copyToList(from,to){
var fromList=eval('document.forms[0].'+from);
var toList=eval('document.forms[0].'+to);
if(toList.options.length > 0 && toList.options[0].value == 'temp'){
toList.options.length=0;
}
var sel=false;
for(i = 0;i < fromList.options.length;i++){
var current=fromList.options[i];
if(current.selected){
sel=true;
if(current.value=='temp'){
alert(' This item cannot be selected !');
return;
}
txt=current.text;
val=current.value;
toList.options[toList.length]=new Option(txt,val);
fromList.options[i]=null;
i--;
}
}
if(!sel) alert(' You haven't chosen any projects yet !');
}
function allSelect(){
var chsen=document.getElementById('chosen');
//If the chsen list box is 0 or the first option value is 'temp'
if(chsen.length && chsen.options[0].value=="temp")
return;
for(var i=0;i<chsen.length;i++){
chsen.options[i].selected=true;
}
//Get the data
function getdata() {
var List = document.forms[0].RoleList;
//Gets a hidden text box object
var roles = document.getElementById("TRoleList");
roles.value = "";
var s = "";
if (List.length != 0) {
for (i = 0; i < List.length; i++) {
s += List.options[i].value + ",";
}
}
roles.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 area from the left </option>
</select>
</td>
</tr>
</form>
</table>
<input type="button" value=" submit " onclick="allSelect()" />yle
<input type="text" style="display:none;" id="TRoleList">
</body>
</html>