View Full Version : Deleting Options in Drop Down Menus
Ben Chivers
06-26-2002, 01:27 PM
Does anyone know how to delete options from a drop down menu at the click of a button.
Any help would be most appreciated.
Many Regards,
Ben Chivers
whackaxe
06-26-2002, 01:35 PM
you cant delete the space i think but you can erase the text and value (you should actully keep the value and change it to something like "voidoption" so you can check if its void) anway you can change an option by using this
document.theform.theselect.options[0].value = "nufink"
document.theform.theselect.options[0].text = ""
to change the vakue of the current selected option use this!
document.theform.theselect.options[theform.theselect.selectedIndex].value = "nufink"
theform.theslect.selectedIndex is the numbe of the currently selected option (well, at te time it is called) it starts at 0 and goes up with more oprions added
tamienne
06-26-2002, 03:07 PM
<Script>
function deleteit() {
document.forms[0].elements[0].options[document.forms[0].elements[0].options.selectedIndex] = null;
document.forms[0].elements[0].options.selectedIndex = 0;
}
</script>
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab </option>
<option value="fiat">Fiat </option>
<option value="audi">Audi </option>
</select>
<input type="button" value="delete it!" onClick="deleteit()">
whackaxe
06-26-2002, 03:33 PM
does that remove the blank space that is left if you use text=""" and value="" as i said?
tamienne
06-26-2002, 03:51 PM
i didn't test in NS but in ie it looks good. Changing the selectedIndex reset the list and deleted the blank line.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.