Dominick
07-11-2003, 09:42 PM
Hello everyone. Sincere thanks in advance for all your help in the past and hopefully the present.
I've modified a function that allows you to select items from a list box and move them to another list box. I then took that function, duplicated it and then reversed the variables so that you can transfer the items back to their original list box. Works in NN 4.7 and late-model NN and IE, so I was thrilled. Feeling quite confident at that point, I added alert messages so that a user would be informed if they tried to move an item from either list box without actually selecting one from the list. That also worked well and I was beside myself with joy - until I decided that I would like to set a maximum number of five values in the second list box - in other words, if a user tries to add a sixth value, they will be alerted that the maximum is five.
I've tried a number of methods, to no avail...Any suggestions would be greatly appreciated.
Regards,
Dominick
==============================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<script language="JavaScript">
<!--
function transferAtoB(object) {
var index = object.dropdownlistA.selectedIndex;
if (index > -1) {
var newoption = new Option(object.dropdownlistA.options[index].text, object.dropdownlistA.options[index].value, true, true);
object.dropdownlistB.options[object.dropdownlistB.length] = newoption;
if (!document.getElementById) history.go(0);
object.dropdownlistA.options[index] = null;
object.dropdownlistA.selectedIndex = 0;
}
else
alert ('Please select an item from List A that you would like to add to List B.');
}
function transferBtoA(object) {
var index = object.dropdownlistB.selectedIndex;
if (index > -1) {
var newoption = new Option(object.dropdownlistB.options[index].text, object.dropdownlistB.options[index].value, true, true);
object.dropdownlistA.options[object.dropdownlistA.length] = newoption;
if (!document.getElementById) history.go(0);
object.dropdownlistB.options[index] = null;
object.dropdownlistB.selectedIndex = 0;
}
else
alert ('Please select an item from List B that you would like to return to List A.');
}
//-->
</script>
</head>
<body>
<form name="MyForm">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" valign="top" width="220">List A</td>
<td width="50"></td>
<td align="center" valign="top" width="220">List B</td>
</tr>
<tr>
<td align="center" valign="top">
<select name="dropdownlistA" size="6" style="width:200px;">
<option value="Option 01">Entry 01</option>
<option value="Option 02">Entry 02</option>
<option value="Option 03">Entry 03</option>
<option value="Option 04">Entry 04</option>
<option value="Option 05">Entry 05</option>
<option value="Option 06">Entry 06</option>
<option value="Option 07">Entry 07</option>
<option value="Option 08">Entry 08</option>
<option value="Option 09">Entry 09</option>
<option value="Option 10">Entry 10</option>
</select>
<br><br>
<input type="button" value="Add to List B" onClick="if (document.images) transferAtoB(this.form)">
</td>
<td> </td>
<td align="center" valign="top">
<select name="dropdownlistB" size="6" style="width:200px;">
</select>
<br><br>
<input type="button" value="Return to List A" onClick="if (document.images) transferBtoA(this.form)">
</td>
</tr>
</table>
</form>
</body>
</html>
I've modified a function that allows you to select items from a list box and move them to another list box. I then took that function, duplicated it and then reversed the variables so that you can transfer the items back to their original list box. Works in NN 4.7 and late-model NN and IE, so I was thrilled. Feeling quite confident at that point, I added alert messages so that a user would be informed if they tried to move an item from either list box without actually selecting one from the list. That also worked well and I was beside myself with joy - until I decided that I would like to set a maximum number of five values in the second list box - in other words, if a user tries to add a sixth value, they will be alerted that the maximum is five.
I've tried a number of methods, to no avail...Any suggestions would be greatly appreciated.
Regards,
Dominick
==============================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<script language="JavaScript">
<!--
function transferAtoB(object) {
var index = object.dropdownlistA.selectedIndex;
if (index > -1) {
var newoption = new Option(object.dropdownlistA.options[index].text, object.dropdownlistA.options[index].value, true, true);
object.dropdownlistB.options[object.dropdownlistB.length] = newoption;
if (!document.getElementById) history.go(0);
object.dropdownlistA.options[index] = null;
object.dropdownlistA.selectedIndex = 0;
}
else
alert ('Please select an item from List A that you would like to add to List B.');
}
function transferBtoA(object) {
var index = object.dropdownlistB.selectedIndex;
if (index > -1) {
var newoption = new Option(object.dropdownlistB.options[index].text, object.dropdownlistB.options[index].value, true, true);
object.dropdownlistA.options[object.dropdownlistA.length] = newoption;
if (!document.getElementById) history.go(0);
object.dropdownlistB.options[index] = null;
object.dropdownlistB.selectedIndex = 0;
}
else
alert ('Please select an item from List B that you would like to return to List A.');
}
//-->
</script>
</head>
<body>
<form name="MyForm">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" valign="top" width="220">List A</td>
<td width="50"></td>
<td align="center" valign="top" width="220">List B</td>
</tr>
<tr>
<td align="center" valign="top">
<select name="dropdownlistA" size="6" style="width:200px;">
<option value="Option 01">Entry 01</option>
<option value="Option 02">Entry 02</option>
<option value="Option 03">Entry 03</option>
<option value="Option 04">Entry 04</option>
<option value="Option 05">Entry 05</option>
<option value="Option 06">Entry 06</option>
<option value="Option 07">Entry 07</option>
<option value="Option 08">Entry 08</option>
<option value="Option 09">Entry 09</option>
<option value="Option 10">Entry 10</option>
</select>
<br><br>
<input type="button" value="Add to List B" onClick="if (document.images) transferAtoB(this.form)">
</td>
<td> </td>
<td align="center" valign="top">
<select name="dropdownlistB" size="6" style="width:200px;">
</select>
<br><br>
<input type="button" value="Return to List A" onClick="if (document.images) transferBtoA(this.form)">
</td>
</tr>
</table>
</form>
</body>
</html>