Javascript code display select values
<p>I am having some problems with finding out if the value is missing or not.</p>

<p>I have the following select box on my screen:</p>

<pre><code>&lt;select id="user_list" onclick="load_user(this)" name="user_list" size="21" style="width:200px;"&gt;   
&lt;option value="1"&gt;Item1&lt;/option&gt;
&lt;option value="2"&gt;Item2&lt;/option&gt;
&lt;option value="4"&gt;Item4&lt;/option&gt;
&lt;/select&gt;
</code></pre>

<p>I am using the following JavaScript:</p>

<pre><code>var userList = document.getElementById("user_list"); 
    for (var i=0;i&lt;userList.options.length; i++) { 
        if (userList.options[i].value != (i+1)) { 
            alert((i+1)+" is missing"); 
            break; 
        } 
        else
        {
        alert((userList.options.length+1)+" is missing"); 
        break;
        }

} 
</code></pre>

<p>The problem I am facing is that if option values 1,2,3,4 are there is replys back with 5 (as that is the next number) which is fine as that is what I want.</p>

<p>If I remove option 3 (like in my select box above) it keeps replying with 4 is missing when it should say 3 is missing.</p>

<p>If i remove the following code:</p>

<pre><code>else
{
alert((userList.options.length+1)+" is missing"); 
break;
}
</code></pre>

<p>it does what I want it to do, but it doesn't get the next value number after checking all values (so it stops after reading the last option in the list).</p>

<p>What it should do is go though all the options in the select box and if one of the values is missing it should alart the one that is missing. If all value numbers are there then it should alart the next available option that is missing.</p>

<p>Can anyone see what I am doing wrong?</p>
