Thanks
I want to remove the option from the previous box so that the user can
only select it once. - This feature only occurs in IE7 - IE6 and
mozilla keeps the first select box scroll bar at the same position in
the select box while IE7 resets it to the top of the list again.
Sorry code as follows...
<html>
<head>
<script language="JavaScript">
function moveOption(form) {
if(form.selone.selectedIndex == -1){
alert("Please select an Option");
}else{
for (var i=0; i<form.selone.options.length;i++)
{
if (form.selone.options[i].selected)
{
addOption(form.seltwo,form.selone.options[i].text,form.selone.options[i].value);
deleteOption(form.selone,i);
}
}
}
}
function addOption(object,text,value) {
var defaultSelected = true;
var selected = true;
var optionName = new Option(text, value, defaultSelected,
selected)
object.options[object.length] = optionName;
}
function deleteOption(object,index) {
object.options[index] = null;
}
</script>
</head>
<body>
<form name="frmMain">
<select name="selone" size="5" style="width:180;height:100;">
<option value=0>0</option>
<option value=10>10</option>
<option value=20>20</option>
<option value=30>30</option>
<option value=40>40</option>
<option value=50>50</option>
<option value=60>60</option>
<option value=70>70</option>
<option value=80>80</option>
<option value=90>90</option>
<option value=100>100</option>
</select>
Button
<input type="button" name="BtnAdd" value=">>"
onClick="moveOption(frmMain);" >
<select name="seltwo" size="5" style="width:180;height:100;">
</select>
</form>
</body>
</html>
RobG wrote:
srt5k wrote:
I have a web page with 2 html multiple select boxes on it, and I use
javascript to dynamicaly copy options from one box to another, before
deleting the option from the first box.
You don't have to copy and delete, just assign the option to the other
select, e.g.:
<select id="selA">
<option>selA 0
<option>selA 1
<option>selA 2
<option>selA 3
</select>
<select id="selB">
<option>selB 0
<option>selB 1
<option>selB 2
<option>selB 3
</select>
<button onclick="
var a = document.getElementById('selA');
var b = document.getElementById('selB');
var idx = a.selectedIndex;
b.options[b.options.length] = a.options[idx];
a.selectedIndex = (idx 0)? idx-1 : 0;
">Move selected A to B</button>
--
Rob