lecture20

lecture20 - PIC 40A Lecture 20: JavaScript Event Handling,...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
PIC 40A Lecture 20: JavaScript Event Handling, navigator , location , window
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
JavaScript Events • notifications of user or browser activity • modeled as JavaScript objects • created by JavaScript and the browser Event-driven programming focuses on detecting and responding to events
Background image of page 2
How do I respond to an event? 1. create an event handler , a script that is designed to respond to a particular event 2. connect the handler to the event ( registration ) Two approaches to handler registration Assign a tag attribute Assign a handler address to a DOM object property
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Registration Example 1 Assign a tag attribute: <head><title>Event Handler Example</title> <script type="text/javascript"> <!-- function load_greeting() { alert(“what up!”);} // --> </script> </head> <body onload=“load_greeting()” ><p></p> </body>
Background image of page 4
Registration Example 2 In a head JavaScript script <script type="text/javascript"> <!-- function message() {alert("Thanks for clicking");} // --> </script> In the body <form id="messageBoard" action=""> <input type="button" name="mybutton" id="mybutton" value=“See a message" /> </form> <script type="text/javascript"> <!-- document.getElementById("mybutton").onclick = message; // --> </script>
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Registration Example 3 In a head JavaScript script <script type="text/javascript"> <!-- function message(s) {alert(s);} //--> </script> In the body <form id="messageBoard" action="">
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/15/2010 for the course PIC 40A taught by Professor Ouellette during the Winter '10 term at UCLA.

Page1 / 22

lecture20 - PIC 40A Lecture 20: JavaScript Event Handling,...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online