<select class="dName" name="dName">
<option SELECTED value="#" DISABLED>========================</option>
<option id="0" value="amensah">Abbey-Mensah, Michael</option>
<option id="1" value="acharya">Acharya, Niraj</option>
<option id="2" value="achonu">Achonu, Geoffrey C.</option>
<option id="3" value="agustin">Agustin, Erie</option>
<option id="4" value="agyemang">Agyemang, Kuragu</option>
</select>
I am using the ID in my Javascript:
if (i[iVar] == $(".dName").find('option:selected').attr('id')) {
To pull which option was selected.
Now let's say I want to delete options #2 for the dName select, instead of changing the #3 to #2 as ID and #4 to #3 as ID, can I use an array? This might be easy but having a 100+ options would make it really time consuming
Is there anyway to change the ID in the dName select so no matter what it is used as an array? Something like:
<option id="[]" value="amensah">Abbey-Mensah, Michael</option>
So if I delete an option in the middle of the list, it will keep the numbering structure in order?
RESOLVED:
if (i[iVar] == $(".dName").find('option:selected').attr('id')) {
Has been changed to:
if (i[iVar] == "the value of selection option") {
AND
document.getElementById('first').innerHTML = phyList[$(".dName").find('option:selected').attr('id')].firstName;
Has been changed to:
document.getElementById('first').innerHTML = phyList[$(".dName").find('option:selected').index()-1].firstName; //.index()-1 because the first option is "=" which is not being used
So I can completely get rid of the ID and not worry about deleting an option statement.
indexof your element on change.valueas the unique identifier, and if you wanted to access which index the option is, you can use jQuery$('select[class]=dName option:selected')this way you can get the selected option