How To Get Selected Option Value in JavaScript?

Jun 12, 2021 . Admin

Hello Friends,

Now let's see example of how to get selected option value example. We will use how to get selected option value in javascript. Here you will learn how to use javascript get selected option value. This is a short guide on get selected option value. Let's get started with how to get selected option value in javascript.

Here i will give you many example how you can get selected option value javascript.

Example : 1
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>JavaScript Get Selected Option Value Example</title>
    </head>
    <body>
        <form>
            Select Your Stream:
            <select id="stud">
                <option value="BCA">BCA</option>
                <option value="BSC.IT">BSC.IT</option>
                <option value="BBA">BBA</option>
                <option value="B.Com">B.Com</option>
            </select>
        </form>

        <p>Click this button and change the selected value.</p>

        <button type="button" onclick="test()">Check it</button>
    </body>
    <script>
        function test() {
            document.getElementById("stud").value = "BSC.IT";
        }
    </script>
</html>
Output :
Select Your Stream: BSC.IT
Example : 2
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>JavaScript Get Selected Option Value Example</title>
    </head>
    <body>

        <form>
            Select your subject:
            <select id="stud">
                <option value="Laravel">Laravel</option>
                <option value="JavaScript">JavaScript</option>
                <option value="Html">Html</option>
                <option value="Php">Php</option>
            </select>
        </form>

        <p>Click this button and change the selected value.</p>

        <button type="button" onclick="test()">Check it</button>
    </body>
    <script>
        function test() {
            document.getElementById("stud").value = "Php";
        }
    </script>
</html>
Output :
Select your subject: Php 

It will help you...

#Javascript