Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Events In Javascript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 148
    Comment on it

    We can handle interaction of javascript with html document with the help of events that take place when user perform some task or when browser performs some manipulation on a page.

    Below are some example of an events:-

    • Loading of page
    • Clicking a button
    • Pressing any key
    • Closing a window,etc.

    For producing javascript coded response, we can use events, which cause a button to produce a message when it get clicked, we can also validate our data with the help of events.

    Below are some commonly use events :-

    onclick event

    This is the most commonly used event which take place when we clicks the button of the mouse. we can also validate our data with the help of this event.

    eg:-

    <html>
       <head>
    
          <script>
    
                function sayHii() {
                   alert("Hii")
                }
    
          </script>
    
       </head>
    
       <body>
          <p>Click On It</p>
    
          <form>
             <input type="button" onclick="sayHii()" value="Hii" />
          </form>
    
       </body>
    </html>
    

    onsubmit event

    This event take place when we try to submit a form.

    eg:-

    <html>
       <head>
    
          <script>
    
                function validate() {
    
                      javascript validation code go here
                }
    
          </script>
    
       </head>
       <body>
    
          <form method="POST" action=" " onsubmit="return validate()">
    
             <input type="submit" value="Submit" />
          </form>
    
       </body>
    </html>
    

    onmouseover and onmouseout

    The onmouseover event take place when we put our mouse cursor over any element and the onmouseout take place when we move our mouse cursor out from that element.

    eg:-

    <html>
       <head>
    
          <script >
    
                function a() {
                   document.write ("Mouse Over");
                }
    
                function b() {
                   document.write ("Mouse Out");
                }
    
    
          </script>
    
       </head>
       <body>
          <p>Bring your mouse inside the block to see the result:</p>
    
          <div onmouseover="a()" onmouseout="b()">
             <h2> This is inside the block </h2>
          </div>
    
       </body>
    </html>
    

 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: