<!--
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
-->
<html>
<head>
<title>ThaiCreate.Com Add/Remove Items</title>
<script language="JavaScript">
function MoveOption(objSourceElement, objTargetElement) {
var aryTempSourceOptions = new Array();
var x = 0;
for (var i = 0; i < objSourceElement.length; i++) {
if (objSourceElement.options[i].selected) {
var intTargetLen = objTargetElement.length++;
objTargetElement.options[intTargetLen].text = objSourceElement.options[i].text;
objTargetElement.options[intTargetLen].value = objSourceElement.options[i].value;
}
else {
var objTempValues = new Object();
objTempValues.text = objSourceElement.options[i].text;
objTempValues.value = objSourceElement.options[i].value;
aryTempSourceOptions[x] = objTempValues;
x++;
}
}
objSourceElement.length = aryTempSourceOptions.length;
for (var i = 0; i < aryTempSourceOptions.length; i++) {
objSourceElement.options[i].text = aryTempSourceOptions[i].text;
objSourceElement.options[i].value = aryTempSourceOptions[i].value;
objSourceElement.options[i].selected = false;
}
}
function checkAllItems()
{
for (var i = 0; i < frmMain.ddlLeft.length; i++) {
frmMain.ddlLeft.options[i].selected = true;
}
for (var i = 0; i < frmMain.ddlRight.length; i++) {
frmMain.ddlRight.options[i].selected = true;
}
}
function removeAllItems()
{
for (var i = 0; i < frmMain.ddlLeft.length; i++) {
frmMain.ddlLeft.options[i].selected = false;
}
for (var i = 0; i < frmMain.ddlRight.length; i++) {
frmMain.ddlRight.options[i].selected = false;
}
}
</script>
</head>
<body onLoad="removeAllItems();">
<form name="frmMain" action="AddRemoveItems.asp" method="post" onSubmit="checkAllItems();">
<table width="353" border="0" cellspacing="4" cellpadding="0">
<tr>
<td><div align="center"><b>Left</b></div></td>
<td rowspan="2"><div align="center">
<input type="button" name="MoveRight" value="Move To Right -> " style="width: 120px;" onClick="MoveOption(this.form.ddlLeft, this.form.ddlRight)">
<br>
<br>
<input type="button" name="MoveLeft" value=" <- Move To Left" style="width: 120px;" onClick="MoveOption(this.form.ddlRight, this.form.ddlLeft)">
</div></td>
<td><div align="center"><b>Right</b></div></td>
</tr>
<tr>
<td>
<select name="ddlLeft" id="ddlLeft" size="12" multiple style="width: 100px;">
<option value="Option 1">Option 1</option>
<option value="Option 2">Option 2</option>
<option value="Option 3">Option 3</option>
<option value="Option 4">Option 4</option>
<option value="Option 5">Option 5</option>
<option value="Option 6">Option 6</option>
<option value="Option 7">Option 7</option>
<option value="Option 8">Option 8</option>
</select>
</td>
<td>
<select name="ddlRight" id="ddlRight" size="12" multiple style="width: 100px;">
</select>
</td>
</tr>
</table>
<br>
<input name="btnSubmit" type="submit" id="btnSubmit" value="Submit">
</form></body></html>
</body>
</html>
AddRemoveItems.asp
<%
'*** By Weerachai Nukitram ***'
'*** http://www.ThaiCreate.Com ***'
%>
<html>
<head>
<title>ThaiCreate.Com Add/Remove Items</title>
</head>
<body>
<%
' *** Left Option ***'
Response.write("<b>- Left -</b><br>")
For Each lmVol in Request.Form("ddlLeft")
IF Trim(lmVol) <> "" Then
Response.write lmVol&"<br>"
End IF
Next
Response.write("<hr>")
' *** Right Option ***'
Response.write("<b>- Right -</b><br>")
For Each lmVol in Request.Form("ddlRight")
IF Trim(lmVol) <> "" Then
Response.write lmVol&"<br>"
End IF
Next
%>
</body>
</html>