Question: I'm having a select box which contains 17 values/options. 

```
<select id="_class" name="_class">
    <option value="0"></option>
    <option value="1">PREKG</option>
    <option value="2">LKG</option>
    <option value="3">UKG</option>
    <option value="4">I</option>
    <option value="5">II</option>
    <option value="6">III</option>
    <option value="7">IV</option>
    <option value="8">V</option>
    <option value="9">VI</option>
    <option value="10">VII</option>
    <option value="11">VIII</option>
    <option value="12">IX</option>
    <option value="13">X</option>
    <option value="14">XI</option>
    <option value="15">XII</option>
    <option value="16">XIII</option>                              
</select>

```

Now, I'm trying to remove the option from 5 to 8. For that, I'm using the following JavaScript code.

```
<script type="text/javascript">
 var _class = document.getElementById("_class");
 for(var i=1; i < _class.length;i++) {
   if(i>=5 && i<=8) {
     _class.remove(i);
   }
 }
</script>

```

But, I'm not getting the expected result, because every time as if the for loop runs, the order of the option is getting changed.

How can I get the desired result?

[Here](http://jsfiddle.net/Gy8j8/) I've attached the Fiddle.

Answer: 
A simpler example: remove number 2 to 4 of a list of 6:
In this list, the digit represents the INDEX in the array:

* 1) one
* 2) two
* 3) three
* 4) four
* 5) five
* 6) six

now if I remove number 2, the rest of the items get a new index:

* 1) one
* 2) three
* 3) four
* 4) five
* 5) six

if I remove number 3 next, I actually hit for:

* 1) one
* 2) three
* 3) five
* 4) six

There's a very simple trick to avoid this: remove in reverse order:
in this example (removing 2 to 4) we remove 4 first:

* 1) one
* 2) two
* 3) three
* 4) four
* 5) five
* 6) six

after removing four, only the indexes higher than four changed, and
they don't matter to us:

* 1) one
* 2) two
* 3) three
* 4) five
* 5) six

now we can remove three:

* 1) one
* 2) two
* 3) five
* 4) six

In programing terms this means turning the for loop around:

```
 for(var i=8; i >= 5;i--) {
    _class.remove(i);
 }

```

See <http://jsfiddle.net/bjelline/XQH54/>

p.s. as you can see, I also changed the loop to only touch
the indexes we really need.
Maybe a bit late, but I had the same issue. Here's my solution.
And thanks @steveukx, your explanation helped me out!

```
function remove(el) {
    for(var i=el.length-1;i>=0;i--) {
        if(el[i].selected)
            el.remove(i);
    }
};

```