JavaScript Form Events


1. submit: This event occurs when a form is submitted.

Syntax:

    <element onsubmit=”functionName()”>


Example:

    <form action=”https://www.tutorialsduniya.com”>
        Name: <input type=”text” />
        <input type=”submit” onsubmit=”myScript” />
    </form>
    <script>
        function myScript()
        {
            alert(“Form is submitted successfully”);
        }
    </script>        


2. reset: This event occurs when a form is reset.

Syntax:

    <element onreset=”functionName()”>


Example:

    <form onreset=”myScript” >
        Name: <input type=”text” />
        <input type=”reset” />
    </form>
    <script>
        function myScript()
        {
            alert(“Form is reset successfully”);
        }
    </script>