<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">function moveOver()
{
var boxLength = document.choiceForm.choiceBox.length;
var selectedItem = document.choiceForm.available.selectedIndex;
var selectedText = document.choiceForm.available.options[selectedItem].text;
var selectedValue = document.choiceForm.available.options[selectedItem].value;
var i;
var isNew = true;
if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
thisitem = document.choiceForm.choiceBox.options[i].text;
if (thisitem == selectedText) {
isNew = false;
break;
}
}
}
if (isNew) {
newoption = new Option(selectedText, selectedValue, false, false);
document.choiceForm.choiceBox.options[boxLength] = newoption;
}
document.choiceForm.available.selectedIndex=-1;
}
function removeMe() {
var boxLength = document.choiceForm.choiceBox.length;
arrSelected = new Array();
var count = 0;
for (i = 0; i < boxLength; i++) {
if (document.choiceForm.choiceBox.options[i].selected) {
arrSelected[count] = document.choiceForm.choiceBox.options[i].value;
}
count++;
}
var x;
for (i = 0; i < boxLength; i++) {
for (x = 0; x < arrSelected.length; x++) {
if (document.choiceForm.choiceBox.options[i].value == arrSelected[x]) {
document.choiceForm.choiceBox.options[i] = null;
}
}
boxLength = document.choiceForm.choiceBox.length;
}
}
function saveMe() {
var strValues = "";
var boxLength = document.choiceForm.choiceBox.length;
var count = 0;
if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
if (count == 0) {
strValues = document.choiceForm.choiceBox.options[i].value;
}
else {
strValues = strValues + "," + document.choiceForm.choiceBox.options[i].value;
}
count++;
}
}
if (strValues.length == 0) {
alert("You have not made any selections");
}
else {
alert("Here are the values you've selected:\r\n" + strValues);
}
}
</script>
</HEAD><BODY>
<center>
<form name="choiceForm">
<table border=0>
<tr>
<td valign="top" width=175>
可得到的选项
<br>
<select name="available" size=10 onchange="moveOver();">
<option value=1>测试1
<option value=2>测试2
<option value=3>测试3
<option value=4>测试4
<option value=5>测试5
<option value=6>测试6
<option value=7>测试7
</select>
</td>
<td valign="top">
你的选择:
<br>
<select multiple name="choiceBox" style="width:150;" size="10">
</select>
</td>
</tr>
<tr>
<td colspan=2 height=10>
<input type="button" value="去除" onclick="removeMe();">
<input type="button" value="得到所选的Value" onclick="saveMe();">
</td>
</tr>
</table>
</form>
</center>
</body></html>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">function moveOver()
{
var boxLength = document.choiceForm.choiceBox.length;
var selectedItem = document.choiceForm.available.selectedIndex;
var selectedText = document.choiceForm.available.options[selectedItem].text;
var selectedValue = document.choiceForm.available.options[selectedItem].value;
var i;
var isNew = true;
if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
thisitem = document.choiceForm.choiceBox.options[i].text;
if (thisitem == selectedText) {
isNew = false;
break;
}
}
}
if (isNew) {
newoption = new Option(selectedText, selectedValue, false, false);
document.choiceForm.choiceBox.options[boxLength] = newoption;
}
document.choiceForm.available.selectedIndex=-1;
}
function removeMe() {
var boxLength = document.choiceForm.choiceBox.length;
arrSelected = new Array();
var count = 0;
for (i = 0; i < boxLength; i++) {
if (document.choiceForm.choiceBox.options[i].selected) {
arrSelected[count] = document.choiceForm.choiceBox.options[i].value;
}
count++;
}
var x;
for (i = 0; i < boxLength; i++) {
for (x = 0; x < arrSelected.length; x++) {
if (document.choiceForm.choiceBox.options[i].value == arrSelected[x]) {
document.choiceForm.choiceBox.options[i] = null;
}
}
boxLength = document.choiceForm.choiceBox.length;
}
}
function saveMe() {
var strValues = "";
var boxLength = document.choiceForm.choiceBox.length;
var count = 0;
if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
if (count == 0) {
strValues = document.choiceForm.choiceBox.options[i].value;
}
else {
strValues = strValues + "," + document.choiceForm.choiceBox.options[i].value;
}
count++;
}
}
if (strValues.length == 0) {
alert("You have not made any selections");
}
else {
alert("Here are the values you've selected:\r\n" + strValues);
}
}
</script>
</HEAD><BODY>
<center>
<form name="choiceForm">
<table border=0>
<tr>
<td valign="top" width=175>
可得到的选项
<br>
<select name="available" size=10 onchange="moveOver();">
<option value=1>测试1
<option value=2>测试2
<option value=3>测试3
<option value=4>测试4
<option value=5>测试5
<option value=6>测试6
<option value=7>测试7
</select>
</td>
<td valign="top">
你的选择:
<br>
<select multiple name="choiceBox" style="width:150;" size="10">
</select>
</td>
</tr>
<tr>
<td colspan=2 height=10>
<input type="button" value="去除" onclick="removeMe();">
<input type="button" value="得到所选的Value" onclick="saveMe();">
</td>
</tr>
</table>
</form>
</center>
</body></html>
function add(selectp,selects)
{
var num,n,i;
num=selectp.length;
n=selects.length;
for(i=0;i<num;i++)
{
if (selectp.selectedIndex==i)
{
selects.length+=1;
selects[n].value=selectp[i].value;
selects[n].text=selectp[i].text;
selectp[i]=null; add(selectp,selects);
n++;
}
}
return false;
}//將多選塊selectp的所有項轉移到selects中
function addall(selectp,selects)
{
var num,n,i;
num=selectp.length;
for(i=0;i<num;i++)
{
n=selects.length;
selects.length+=1;
selects[n].value=selectp[0].value;
selects[n].text=selectp[0].text;
selectp[0]=null;
n++;
}
return false;
}