0

I'm trying to get the value of a drop down box and keep getting the error Uncaught TypeError: Cannot read property 'selectedIndex' of null.

Heres my code:

JS

expirationYearSelectedIndex = document.getElementById("selYear").selectedIndex;
    console.log("expirationYearSelectedIndex = " + expirationYearSelectedIndex);

    expirationYear = document.getElementById("selYear").options[expirationYearSelectedIndex].value;
    console.log("expirationYear = " + expirationYear);

HTML

<form action="">
    <select id="SelYear" name="selYear">
        <option selected value=""> Select a Major....</option>
        <option value="Comptuer Information Systems"> CIS</option>
        <option value="Math"> M</option>
        <option value="CS"> CS</option>
        <option value="History"> H</option>
    </select>
</form>

1 Answer 1

1

Missed the capital S on the ID name <select id="SelYear" name="selYear">

document.getElementById("SelYear");
Sign up to request clarification or add additional context in comments.

3 Comments

Guess I just needed another set of eyes! Thanks so much I have looked and looked over it and thought I was coding it wrong!! Thanks so much!
No problem, don't forget to mark the correct answer :)
Will do! Just have to wait 6 more minutes before itll let me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.