Clip Art Events
Pierce Home
Computer Science 555 Website Development using JavaScript and AJAX - 3 Units
Section:
3179
Instructor:
Brad Gilbert
Pierce Mailbox:
612
Email:
pierce@wavethunder.com
Wednesday Office Hours:
5:00 -   5:40 PM COSC 1507
Wednesday Lab:
5:45 -   7:50 PM COSC 1507
Wednesday Lecture:
7:55 - 10:00 PM MATH 1511
Other classes:
CS-575
events
Question:

What are events?

Answer:

Events are actions that ultimately result from user actions. For example, window.onload occurs because the user typed your URL in the browser address bar, or clicked a link to load a new page.

Question:

What are some specific events?

Answer:

Events include:

  • window.onload
  • window.onunload
  • onclick
  • onkeypress
  • onmouseover
  • onmouseout
  • ...

A complete list and their descriptions may be found at:
w3schools JavaScript Event Reference

Question:

How do I manage events?

Answer:

Assign event handlers (functions) to the events of objects. For example:

    document.getElementById("MyButton").onclick = BtnClick;
    
    function BtnClick() {
        alert("You click MyButton!");
    }
    

Notice that when you assign the event handler, you do not use (), otherwise that would be a function call instead of assigning the handler to the event. In other words, the function would execute immediately, instead of waiting for the event to cause the function to execute.

    // do not use () when assigning an event handler to an object.
    // the below code will not perform properly.
    document.getElementById("MyButton").onclick = BtnClick();
    
Question:

How can I pass parameters to event handlers?

Answer:

That requires an advanced use of the function object.
Please review the source code for the Event Example in week 7.

Brad Gilbert · Fall 2011
Computer Science · Pierce College · Woodland Hills CA · 818-719-6401