Javascript DOM Event Assign Event Handler

Description

Javascript DOM Event Assign Event Handler

View in separate window


<!DOCTYPE html>

<html>
<head>
   <title>Assigning an Event Handler</title>
   <script language="JavaScript">
      function AssignHandler()/*from   w ww  .j  ava2 s . c o  m*/
      {
         // Subscribe to the click event.
         document.getElementById(
            "btnClickMe").onclick=SayHello;
         
         // Display a subscription message.
         document.getElementById("demo").innerHTML = "Button Assigned";
      }
      
      function SayHello()
      {
         // Display a message.
         document.getElementById("demo").innerHTML = "Hello There";
      }
   </script>
</head>

<body>
   <h1>Assigning an Event Handler</h1>
   
   <p id="demo"></p>
   <input id="btnAssign"
          type="button"
          value="Assign the Event Handler"
          onclick="AssignHandler()" />
   <input id="btnClickMe"
          type="button"
          value="Click Me" />
</body>
</html>



PreviousNext

Related