HTML - attributes - onsubmit

revision:


Content

"onsubmit" attribute : when a for is submitted syntax some examples


"onsubmit" attribute : when a for is submitted

top

The onsubmit attribute fires when a form is submitted. Supported HTML tags: <form>


syntax

top

<element onsubmit="script"></element>

script: the script to be run on onsubmit.


some examples

top

When you submit the form, a function is triggered which alerts some text.

Enter name:

codes:
                    <p class="spec">When you submit the form, a function is 
                    triggered which alerts some text.</p>
                    <form style="margin-left:3vw;" action="action_page.php" 
                    onsubmit="subFunction()">
                        <p class="spec">Enter name: <input type="text" 
                        name="fname"></p>
                        <input type="submit" value="Submit">
                    </form>
                    <p class="spec" style="margin-left:3vw;"id="idea-1"></p>
                    <script>
                        function subFunction() {
                            alert("the form has been submitted");
                        }
                    </script>
                

First Name:
Last Name:


codes:
                    <form style="margin-left:3vw;" onsubmit = "easyGoing()">                                                                        
                        <p class="spec"> First Name:<input type = "text"
                        value = "" /><br/>
                        Last Name:<input type = "text" value = ""/></p><br/>
                        <input type = "submit" value = "Submit"/>
                    </form>
                    <script>
                        function easyGoing() {
                            alert("Form submitted successfully.") ;
                        }
                    </script>