-
I have a multiple select list box that is enabled and disabled by a Checkbox, what I want to be able to do is clear out an pre-selected items after the box has been disabled. At the minute when I re-enable the box the prevoiusly selected items are still showing as being selected.
The code I'm trying to use is.
<input type="checkbox" name="chk1" value="chk1" onClick="if (chk1.checked) document.frmMethods.EG.disabled=true; else document.frmMethods.EG.disabled=false; ">
<select name="EG" size="4" multiple onChange="if (EG.disabled) EG.selectedIndex=0;">
Thanks
-
Check out my response in this thread.
-
-
Wierd.. I copied and pasted it right from the URL line.. it looks like the entire thread got deleted...
I'll dig up my code and repost it for ya...
-
Ok.. first off, I'm unclear whether you really want to 'clear' the listbox or just un-select the selected items so I'll post both:
Code:
//Remove all items from a listbox
//Javascript
var colOptions = frmMyForm.lstMyList.options;
var intList;
for (intList=colOptions .length-1; intList > -1; intList--)
colOptions .remove(intList);
'-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
'VBScript
Dim colOptions
Dim intList
Set colOptions = frmMyForm.lstMyList.options
For intList=colOptions.length-1 to 0 Step -1
colOptions.remove(intList)
Next
Set colOptions = Nothing
'-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
//Javascript
//Unselect any selected Items
var colOptions = frmMyForm.lstMyList.options;
var intList;
for (intList=0;intList<colOptions .length; intList++)
if (colOptions[intList].selected)
colOptions[intList].selected=false;
'-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
'VBScript
Dim colOptions
Dim intList
Set colOptions = frmMyForm.lstMyList.options
For intList=0 to colOptions.length
If colOptions(intList).selected Then
colOptions(intList).selected=False
End If
Next
Set colOptions = Nothing
-
Thank-you, I wanted to unselect the items.