Write a program to print selected item from select box

 Name of Program - To print selected item from select box

Code Input -

<!--JavaScript - Print Selected Item from SelectBox.-->

<html>

    <head>

        <title>JavaScript - Print Selected Item from SelectBox.</title>

        <script type="text/javascript">

            function printSelectedItem() {

                var e = document.getElementById("cities");

                var selectedItem = e.options[e.selectedIndex].value;

                alert(selectedItem);

            }

        </script>

    </head>

    <body style="text-align: center;">

        <h1>JavaScript - Print Selected Item from SelectBox.</h1>

        <big>Select your favourite city:</big>

        <select id="cities" onchange="printSelectedItem()">

            <option value="Haryana">Haryana</option>

            <option value="Chandigarh">Chandigarh</option>

            <option value="Punjabss">Punjab</option>

        </select>

    </body>

</html>


Code Output- 



No comments

Plz.... Don't enter any spam message