Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Difference b/w onClick() and onSubmit() Event in Javascript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 8.14k
    Comment on it

    Hello readers , today in my blog I would like to discuss about the difference b/w the onClick and onSubmit Events .

    Below is the difference b/w them :-

     


    Below is a example showing the use of onSubmit() :-

    <html>
    
    <head>
    
    <script type = "text/javascript" >
    
    <!--function validate() { all validation goes here ......... return either true or false}//--></script>
    
    </head>
    
    
    <body>
    
    <form method = "POST" action = "t.cgi"onsubmit = "return validate()" > .......
    
    <input type = "submit" value = "Submit" />
    
    </form>
    
    </body >
    
    </html>

    In this example, we are calling a validate () function before submitting the form data to the server.  If the validate() function returns true the form we get submitted to the server otherwise it will not submit.

    Now below is the example showing the use of onClick () event :-

    <html>
    
    <head>
    
    <script type="text/javascript">
    
    <!-- function sayHello() { alert("Hello World")}//-->
    
    </script>
    
    </head>
    
    <body>
    
    <input type="button" onclick="sayHello()" value="Say Hello" />
    
    </body>
    
    </html>

    In this example,  when the user clicks over the Hello button then the onClick() Event will occur and would trigger the sayHello() function.

    Conclusion:-

    I hope with the help of the above example anyone can easily make out a difference b/w the onSubmit () and onClick () Events.

    Difference b/w onClick() and onSubmit() Event in Javascript

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: