Saturday, October 4, 2014

Creating Events and Objects in Java Script

Events  

The  objects  in a Web pages are organized in a hierarchy.  All  objects have properties and methods. In addition, some objects also have "events".   Events are things that happen, usually user actions, that are associated with an object.  The "event handler" is a command that is used to specify actions in response to an event.  Below are some of the most common events:

• onLoad -   occurs when a page loads in a browser
• onUnload  - occurs just before the user exits a page    
 • onMouseOver -  occurs when you point to an object
• onMouseOut -    occurs when you point away from an object
• onSubmit - occurs when you submit a form
• onClick  - occurs when an object is clicked

Events and Objects  

Events are things that happen, actions, that are associated with an object.    Below are some common events and the object they are associaated with:
 
Event                             Object
onLoad                           Body
 onUnload                       Body
onMouseOver                Link, Button
 onMouseOut                 Link, Button
onSubmit                       Form
onClick                         Button, Checkbox, Submit, Reset, Link
 Example:                  <FORM onSubmit="functionName()">  

Image Rollover 

Replacing one image with a second image when the user moves the mouse over it is called a "rollover".  The events called for are the "onMouseOver" and "onMouseOut". The object used with these events can be a link or a button.  

Image Rollover Example  

• With the "window.html" file open, View the Source
 • Put the cursor after the line  "<A HREF=" and enter:
 <P> <A HREF="URL" onMouseOver="document.hot.src='hot1.gif'" onMouseOut="document.hot.src='hot2.gif'"> <IMG name="hot" src="hot2.gir"> </A>
• Save the changes and Refresh the page.   

No comments:

Post a Comment