Guest grunt_lord Posted March 17, 2006 Share Posted March 17, 2006 Hi,I just want to know how it can be possible to remove all the <options> that are inside a <select>. I'm getting the data via an AJAX request (using prototype) and I want to clear the list before I show the result.Thanks a lot in advance,Blaise Bernier Link to comment Share on other sites More sharing options...
Chocolate570 Posted March 17, 2006 Share Posted March 17, 2006 Use this. <script type="text/javascript">function clrSel(id){x=document.getElementById(id);y=x.options;for(z=0;z<y.length;z++){x.removeChild(y[z]);}}</script> That should work. First time I've tried out removeChild, so please don't hesitate to blame me for giving you a fault script in the likely event that this thing blows up. :)Thanks,Choco Link to comment Share on other sites More sharing options...
aspnetguy Posted March 17, 2006 Share Posted March 17, 2006 actually an easier way is this x=document.getElementById(id);x.options.length = 0; I am pretty sure that works. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now