Remove Items from Select List

[Total: 0    Average: 0/5]

This example removes all the items in the list of a select list.

Body Code:

<form name=exf1>
<select name=s1 size=10>
    <option value="1">One
    <option>Two
    <option>Three
    <option>Four
    <option>Five
    <option>Six
    <option>Seven
    <option>Eight
    <option>Nine
    <option>Ten
</select>
</form>
<script>
function doIt() { 
  var srcLength = document.exf1.s1.options.length; 
  for(var i=0;i<srcLength;i++)
    document.exf1.s1.options.remove(i);  
}
function doThis() {
  while(document.exf1.s1.options.length>0)
    document.exf1.s1.options.remove(0);
}
function nsDo() {
  var srcLength = document.exf1.s1.options.length; 
  for(var i=srcLength;i>=0;i--)
    document.exf1.s1.options[i]=null;  
}
</script>
<a href="javascript:doIt()">remove all of them</a>
<BR><BR>
<a href="javascript:doThis()">remove the all the new way</a>
<BR><BR>
<a href="javascript:nsDo()">NS do it</a>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *