views:

64

answers:

2

Hello,

I have a html select box. And a search field (input type)

When i Search for something new a javascript function first clears the selectfield

But Javascript gives the following error:

gs.options.remove is not a function

This is the function

 function clearScholen()
  {
    for (var i=gs.options.length;i>=0;i--)
    {
      gs.options.remove(i); 
    }  
  }

and the value of gs =

<select style="width: 420px; height: 150px;" name="selectbox" size="5">

Whats going wrong?

+2  A: 

If I understand you correctly, you want to clear the search field (which is working) and reset the select drop down.
If that's the case, you want:

gs.selectedIndex = -1;

e.g.

function clearScholen()
  {
       gs.selectedIndex = -1;

  }

assuming that gs is previously defined

Jonathan Fingland
+1  A: 

I guess in your example "gs" doesnt reference a selectbox.

Removing all the options

 function removeAllOptions(selectbox) 
 {
   var i;
   for(i=selectbox.options.length-1;i>=0;i--)
   { 
     selectbox.remove(i); 
   }
 }

Removing Selected Options

function removeOptions(selectbox)
{
  var i;
  for (i=selectbox.options.length-1;i>=0;i--) 
  {
      if(selectbox.options[i].selected)
          selectbox.remove(i);     
  }
}
Paul Rowland