0

I'm trying to get the value of a select element in HTML with JavaScript but for some reason it says it's null and throws an error.

I get the following error on my browser:

script.js:5 Uncaught TypeError: Cannot read property 'value' of null
at script.js:5

HTML:

    <!DOCTYPE html>
    <html lang="gr">
    <head>
        <link rel="stylesheet" href="styles.css">
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=2.0">
        <title>Document</title>
        <script src="script.js"></script>
    </head>
    <body>
        <header>
            <h1>3o Webex Links</h1>
            <nav>
                <ul>
                    <li><a href="index.html">Autojoin</a></li>
                    <li><a href>Links</a></li>
                </ul>
            </nav>
        </header>
        <section>
            <select id="class">
                <option value="default">Τμήμα</option>
                <option value="default">--</option>
                <option value="B1">B1</option>
                <option value="B2">B2</option>
             

   <option value="B3">B3</option>
            <option value="B4">B4</option>
            <option value="B5">B5</option>
        </select>
        <select id="abc">
            <option value="default">abc</option>
            <option value="default">--</option>
            <option value="a">a</option>
            <option value="b">b</option>
        </select>
        <br>
        <a href="" id="link"></a>
    </section>
    <footer>
        Footer
    </footer>
    </body>
    </html>

JavaScript:

let dt=new Date();
let secs=dt.getSeconds() + (60 * dt.getMinutes()) + (60 * 60 * dt.getHours());


let classValue=document.getElementById("class").value;
let abcValue=document.getElementById("abc").value;

let link=document.getElementById("link").href;
let linktext=document.getElementById("link").textContent;

Sorry if that's a dumb question, I'ts my first time using JavaScript like that.

0 Answers0