SoFunction
Updated on 2025-02-28

[IE&FireFox Compatible] JS to select operations

Today, I used two drop-down boxes to dynamically add options in select. When I used them normally under IE tests but couldn't use them normally in FireFox, I was not very familiar with scripts, so I searched the Internet and found that they were a little different when adding options dynamically.

Let me write him down below, maybe I can use it in the future:

Dynamically delete all options in select:
    function deleteAllOptions(sel){
      =0;
    }

Dynamically delete an option in select:
    function deleteOption(sel,indx){
      (indx);
    }

Dynamically add item option in select:
    function addOption(sel,text,value){
      (new Option(text,value));
    }

The above tests were successfully tested in IE and FireFox, and I hope you can use them in the future.
In fact, standard DOM operations are also OK, that is, appendChild, removeChild, etc. :)