Link to home
Start Free TrialLog in
Avatar of ARACK04
ARACK04

asked on

Clearing options collection of Javascript select

Is there a fast way to clear all items from a javascript select?  I've got about 100,000 items in there, returned from some query, and I want to simply dump its contents before the page posts back.  Saying:

$get(name).options.length = 0

took too long, and

$get(name).options = new Array();  threw an exception.  Is there some other way?
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ARACK04
ARACK04

ASKER

$get is part of the Microsoft AJAX JavaScript library - it's a replacement for document.getElementById

Despite being part of the "AJAX" library, it's pure javascript, and doesn't involve the XMLHttpRequestObject, so it's not causing my slowdown.

I tried setting length  = 0 - for a dropdown of about 7,000 items it took about a half a second, and the time just skyrockets as it increases to 100,000.

If this is the fastest I can get, then I guess I have to look elsewhere.  Thanks.
Have you tried:
$get("selectId").options=null;
OR
$get("selectId").options=new Array();
Avatar of ARACK04

ASKER

yeah, tried them both, both slow.  Thanks for the help.