While troubleshooting thread216-1697987, I ran into something I do not understand. Can anyone explain to me why the .remove() is not necessary? If it's uncommented, the function removes 2 items from the source select
-Geates
Code:
<!DOCTYPE html>
<html>
<HEAD>
<title>Mulitiple swap on click</title>
<SCRIPT LANGUAGE="JavaScript">
function moveRight(index) {
option = document.choiceForm.available.options[index];
option.selected = false;
document.choiceForm.choiceBox.add(option);
//document.choiceForm.available.remove(index);
}
function moveLeft(index){
option = document.choiceForm.choiceBox.options[index];
option.selected = false;
document.choiceForm.available.add(option);
//document.choiceForm.choiceBox.remove(index);
}
function saveMe() {
var strValues = "";
for (i = 0; i < document.choiceForm.choiceBox.length; i++) {
strValues = strValues + ',' + document.choiceForm.choiceBox.options[i].value;
}
strValues = strValues.substr(1);
if (strValues.length == 0) {
alert("You have made no selection(s)");
}
else {
alert("Here are the values you've selected:\r\n" + strValues);
choiceForm.valuesForInsert.value = strValues;
choiceForm.submit();
}
}
</script>
</HEAD>
<BODY>
<form name="choiceForm" action="#" method="post">
<input type="hidden" name="selectedValues" value="0">
<input type="hidden" name="valuesForInsert" value="0">
<table border="0">
<tr>
<td valign="top" width=175>Available Countries:<br>
<select name="available" size=10 onclick="moveRight(this.selectedIndex);">
<option value="1">Australia
<option value="2">New Zealand
<option value="3">USA
<option value="4">Canada
<option value="5">England
<option value="6">Switzerland
<option value="7">Russia
<option value="8">France
<option value="9">Italy
<option value="10">Samoa
</select>
</td>
<td valign="top">
Your Choices:<br>
<select multiple name="choiceBox" style="width:150;" size="10" onclick="moveLeft(this.selectedIndex);"></select>
</td>
</tr>
<tr>
<td colspan=2 height=10><input type="button" value="Get Selected Values" onclick="saveMe();"></td>
</tr>
</table>
</form>
</body>
</html>
-Geates