Menu ▼

Previous Next

Change event in JavaScript :

Onchange event will be fired when control value has been changed.

Example:
-------------

Select the country name from the dropdown


Code Sample :

<html>

<head>

    <title>Onchange event example in JavaScript</title>

    <script language="Javascript">

 

        function selctcntry(evt, t) {

            if (t.selectedIndex > 0)

                document.getElementById("Text1").value = t.value;

            else

                document.getElementById("Text1").value = "";

        }

 

    </script>

</head>

<body>

    <table align="center">

        <tr>

            <td>

                <input type="text" id="Text1" />

            </td>

        </tr>

        <tr>

            <td>

                Select the country name from the dropdown

            </td>

        </tr>

        <tr>

            <td>

                <select onchange="selctcntry(event,this);">

                    <option value="India">Select</option>

                    <option value="India">India</option>

                    <option value="USA">USA</option>

                    <option value="China">China</option>

                    <option value="Japan">Japan</option>

                    <option value="Canada">Canada</option>

                </select>

            </td>

        </tr>

    </table>

</body>

</html>

 

 

Previous Next




Search dotnetlearners.com