In This Javascript Tutorial we will See How To Add A Option To Select From Input Text Value On Button Onclick Event Using JS And Netbeans Editor .

Subscribe : https://www.youtube.com/channel/UCS3W5vFugqi6QcsoAIHcMpw

Project Source Code:


<!DOCTYPE html>
<html>
    <head>
        <title>Add New Option</title>
        <meta charset="windows-1252">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
      
        <select id="select">
            <option value="java">Java</option>
            <option value="c#">C#</option>
        </select>
        <input type="text" id="val">
        <button onclick="insertValue();">Add</button>

        <script>
            
            function insertValue()
            {
                var select = document.getElementById("select"),
                    txtVal = document.getElementById("val").value,
                    newOption = document.createElement("OPTION"),
                    newOptionVal = document.createTextNode(txtVal);
             
                newOption.appendChild(newOptionVal);
                select.insertBefore(newOption,select.firstChild);
            }
            
        </script>

    </body>
</html>

#javascript #js

How To Add Option To Select Tag From Input Text using Javascript [ with Source code ]
2.40 GEEK