How to remove options in select?

Hi,

it is clear how to add options:
var opts = dhxForm.getOptions(name);
opts.add(new Option(text, value));

But how to remove them?

You may use remove method

opts.remove(index);

Hi,

I struggle with the method and the index. This is how I define the options
var opts = partForm.getOptions(“partList”);

Then I get some new options:
for (var i=0;i<numParts;i++) {
opts.add(new Option(partForm.getItemValue(“partNumber_”+i)), i);
}

How to call the method:
opts.remove(1);
or
opts.remove(“partNumber_0”)

Both end with
opts.remove is not a function.

Unfortunately we cannot reproduce this issue locally. Please provide us any kind of sample or a demo link where we can reproduce an error.

Here is a demo.

Enter 222 in the field “drawing number” and click “search in database”. If you click this several times, “found part numbers” will show the the found part numbers as many times as you have clicked.
I want to see only the last 2 part numbers.
I have disabled opts.remove because I dont understand the usage.

By the way: the form works well in Firfox but doesnt work in IE8.
Completed Demo2.zip (245 KB)

Hi,

I found a solution:

if (opts.length>0) opts.length = 0;

Hi,
i have the same problem… but i want to remove only few items from select… and “opts.remove(index);” is working only in chrome… I`m using v.3.0 beta form… is there any solution to fix it? thanks…

dhxForm.getOptions(name); method returns select DOM object. This object has remove() method, which receives one parameter - index of the option.
If you want delete few option from select box you should call remove() method one by one.

Thanks for responce…
i`m calling it one by one… : optionsP.remove(i);…

  • but in FF it provide an error “optionsP.remove is not a function”… and thats all…??

  • in chrome it works (remove selected option)…

Can you provide complete demo where we can reproduce this issue? docs.dhtmlx.com/doku.php?id=othe … leted_demo

Hi Olga,

I got the same problem as b_granko: remove is not a function. You got already my demo.
For my application, where I needed to remove all options, I found a solution as described above. But remove doesnt work.

Can you point me please on post with your demo?