Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selection box population/depopulation

Status
Not open for further replies.

DANZIG

Technical User
Mar 8, 2001
142
US
Hello,
How can I handle the de-population of selection boxes?
Code:
<script type="text/javascript">
function put() {
   var len = DevicesList.SelectedDevices.options.length;
   txt=DevicesList.AvailableDevices.options[DevicesList.AvailableDevices.selectedIndex].text;
   valu=DevicesList.AvailableDevices.options[DevicesList.AvailableDevices.selectedIndex].value;
   if (valu != '') {
      DevicesList.SelectedDevices.options[len] = new Option(txt, valu);
   }
}

function remove() {
   		var len2 = DevicesList.SelectedDevices.options.length;
      	DevicesList.SelectedDevices.selectedIndex = null
   
}

</script>

The put() function works I think I was given that by somebody here. what I'm wanting to do is to remove from the DevicesList.SelectedDevices list if it is clicked on and can not figure out how to remove from that list.

Any Ideas?



Thanks, Danzig
 
This should do it:
Code:
function remove() {
   DevicesList.SelectedDevices.options[DevicesList.SelectedDevices.selectedIndex] = null
}

-kaht

banghead.gif
 
The following function will loop through the select field and remove any ones that are selected.
Code:
function removeDate(){
	submitMe=false;
	for (var i=1;i<document.formName.dateField.options.length;i++){
		if (document.formName.dateField.options[i].selected == true){
			document.formName.dateField.options[i]=null;
		}
	}
}
 
Or for your purposes:
Code:
function removeDevice(){
    var f = document.DevicesList.AvailableDevices.options;
    for (var i=1;i<f.length;i++){
        if (f[i].selected == true){
            f[i]=null;
        }
    }
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top