Geeks With Blogs

News

Agha Usman Ahmed JILAWATAN

On making every AJAX call I cannot just keep filling the drop down list, as I have to clear the dropdown after every success call.

So I need a function which is capable of making the drop down list empty.

 

function ClearDropDown(ddl)

{
  var len = ddl.options.length;
    for (i=0; i<len; i++) {
       ddl.remove(0); //It is 0 (zero) intentionally
    }
}
Posted on Saturday, November 1, 2008 12:33 AM | Back to top


Comments on this post: Clear Items from Drop Down using Java script

# re: Clear Items from Drop Down using Java script
Requesting Gravatar...
how about:
while(ddl.option.length > 0)
ddl.remove(0);

Just a thought.
~Lee
Left by Lee Brandt on Nov 01, 2008 10:54 AM

# re: Clear Items from Drop Down using Java script
Requesting Gravatar...
this will help you....
ddl.length = 0

it avoids use of iterator(for,while loop)
Left by Lokesh on Jun 29, 2009 7:54 PM

# re: Clear Items from Drop Down using Java script
Requesting Gravatar...
It is not required to loop.
set the length to 0,

$get("cmbCustomers").options.length = 0;
Left by Satyadeep on Jan 24, 2010 7:23 PM

# re: Clear Items from Drop Down using Java script
Requesting Gravatar...
Thanks for the code. I was looking for the same.
Left by ashish on Feb 02, 2011 8:47 PM

Your comment:
 (will show your gravatar)


Copyright © Agha Usman Ahmed | Powered by: GeeksWithBlogs.net | Join free