Jump to content

Clearing a <select>


Guest grunt_lord

Recommended Posts

Guest grunt_lord

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...