Busted Mug

A blog that documents solutions to the most frustrating problems that occur during development in technologies such as Java, XML, AJAX, SQL, CSS and others that make me want to throw my coffee mug against the cube wall.

Friday, December 01, 2006

Clearing all options from a select

OUCH! I wrote this post to only later learn that doing anything like this:
if (this.selectedDates.length == 0) document.getElementById(this.listName).options[0] = new Option("","");
is just dumb. A million times better solution is:
document.getElementById(this.listName).length = 0;
Don't you hate when an answer is blindingly obvious? I just figured that length would be read only. Oh well.

0 Comments:

Post a Comment

<< Home