Posted by : Sudhir Chekuri Saturday, 10 March 2018


Event handlers are used to execute a function based on the action performed by the user like onclick, onload, onmouseover etc

In the below example 3 buttons are available on the web page - Touch me 1, Touch me 2 and Touch me 3
onClick event is fired when user clicks on each button.
Alert boxes are displayed on user button click.
Touch me 1 - Alert button code is written in html tag.
Touch me 2 - Function named "first" is called on onClick.
Touch me 3 - Function named "second" is called by passing a parameter named "a".

Example code for onClick event handler

<!DOCTYPE html>
<html>

  <head>
 
   <script type="text/javascript">
   
      function first()
      {
     
        alert('Without parameter');
      }
      function second(a)
      {
     
         alert('With parameter '+a);
      }
   
   
    </script>
 
  </head>

  <body>
    <form>
      <!--alert box code in click event-->
      <input type="button" value="Touch me 1" onClick="alert('Hello')" />
      <!--Function called in click event-->
      <input type="button" value="Touch me 2" onClick="first()" />
      <!--Function with parameter called in click event-->
      <input type="button" value="Touch me 3" onClick="second('Hello')" />
    </form>
 
  </body>

</html>

Output



{ 14 comments ... read them below or Comment }

  1. This comment has been removed by the author.

    ReplyDelete
  2. I am a regular reader of your blog and being students it is great to read that your responsibilities have not prevented you from continuing your study and other activities. Love
    python training in tambaram | python training in annanagar | python training in jayanagar

    ReplyDelete
  3. Were a gaggle of volunteers as well as starting off a brand new gumption within a community. Your blog furnished us precious details to be effective on. You've got completed any amazing work!

    Data Science Training in Chennai | Data Science course in anna nagar

    Data Science course in chennai | Data science course in Bangalore

    Data Science course in marathahalli | Data Science course in btm layout

    ReplyDelete
  4. It's very useful blog post with inforamtive and insightful content and i had good experience with this information.I have gone through CRS Info Solutions Home which really nice. Learn more details About Us of CRS info solutions. Here you can see the Courses CRS Info Solutions full list. Find Student Registration page and register now.Find this real time DevOps Training and great teaching. Join now on Selenium Training online course. Upskill career with Tableau training by crs info solutions. Latest trending course is Salesforce Lightning training with excellent jobs.

    ReplyDelete
  5. it was a wonderful chance to visit this kind of site and I am happy to know. thank you so much for giving us a chance to have this opportunity.. This is the exact information I am been searching for, Thanks for sharing the required infos with the clear update and required points.



    Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery





    ReplyDelete
  6. You actually make it look so easy with your performance but I find this matter to be actually something which I think I would never comprehend. It seems too complicated and extremely broad for me. I'm looking forward to your next post, I’ll try to get the hang of it!
    Angular js Training in Chenai

    Angular js Training in Velachery

    Angular js Training in Tambaram

    Angular js Training in Porur

    Angular js Training in Omr
    Angular js Training in Annanagar

    ReplyDelete
  7. I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly.
    IELTS Coaching in chennai

    German Classes in Chennai

    GRE Coaching Classes in Chennai

    TOEFL Coaching in Chennai

    Spoken english classes in chennai | Communication training

    ReplyDelete

Followers

Total Pageviews

Powered by Blogger.

- Copyright © 2013 DevStudent - Metrominimalist - Powered by Blogger - Designed by Johanes Djogan -