Dynamically populating a dropdown with jQuery
<p>How do I remove all the  values from a dropdown list using jQuery?</p>

<pre><code>idnum = "item-7";
</code></pre>

<p>which populates a dropdown with 7 items.  I could have an "item-3" which would populate a dropdown with three items.  What I'm trying to do is select a button which could have an id value of "item-X" where X is the number of entries to populate so it could be different based on whatever button I click.  I want to clear the select list and repopulate it with a different number on each button click.</p>

<p>Here is my code:</p>

<pre><code> $('#items').empty();

 // alert('I was clicked, my id is ' + $(this).attr('id')); 
 var idnum = $(this).attr('id');
 var pos = idnum.lastIndexOf("-");
 var num = idnum.substring(pos + 1);

 // alert("You have " + num);

 // var numbers = [1, 2, 3, 4, 5]; 
 var numbers = new Array(num - 1);

 for (i = 0; i &lt; num; i++) {
   numbers[i] = i + 1;
 }

 for (i=0;i&lt;numbers.length;i++){ 
   $('&lt;option/&gt;').val(numbers[i]).html(numbers[i]).appendTo('#items'); 
 }
</code></pre>

<p>I tried empty() and remove() and they're both not working.</p>
