I have a listbox on a page:
<select id="user_list" name="user_list" size="21" style="width:200px;">
<option value=1>User 1</option>
<option value=2>User 2</option>
<option value=3>User 3</option>
<option value=5>User 5</option>
<option value=6>User 6</option>
</select>
And if I select a item I can get the current value by using the following code:
var el = document.getElementById("user_list");
var val = el[el.selectedIndex].value;
alert(val);
However, the problem I am having is that I want to be able to search the user_list (start from 1) for the next avaliable number (in my example above it will alert 4, as that is missing)
But I have tried using:
var el = document.getElementById("user_list");
var val = el[4].value;
alert(val);
but it doesn’t work, does anyone know what I am doing wrong?
My guess is that var val = el[4].value; is wrong.. ?
it works well.
http://jsfiddle.net/ubpn7/