[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 413
  • Last Modified:

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?
0
ARACK04
Asked:
ARACK04
  • 2
  • 2
1 Solution
 
hieloCommented:
if you give the select list an id:
<select id="someList">...</select>
then you can simply say:
document.getElelementById("someList").options.length=0;

That will be the fastest. What does $get() do for you? I suspect it is doing an AJAX call. If anything, the AJAX call is the one that is causing the delay.
0
 
ARACK04Author Commented:
$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.
0
 
hieloCommented:
Have you tried:
$get("selectId").options=null;
OR
$get("selectId").options=new Array();
0
 
ARACK04Author Commented:
yeah, tried them both, both slow.  Thanks for the help.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now