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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clearing A Select Element of options with javascript

Status
Not open for further replies.

williambq

IS-IT--Management
Feb 12, 2009
1
US
this is follow up to thread216-1121894
I needed to dynamically clear a drop down before re-ajaxing the results and ran into this same issue. setting options to null in a for loop has some issues. looks like this previous thread decided that a decrementing for loop worked okay, but this is even simpler:

while($('fm_QueuesDropDown').options.length > 0) {
$('fm_QueuesDropDown').options[0] = null;
}

the problem with the [forward] for loop is it gets rid of the first (0) option first and then gets a bit confused. using the while loop alleviates keeping track of any order of the options.
-williambq
wbq dot us
chiptard dot com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top