Mega Code Archive

 
Categories / JavaScript Tutorial / Event
 

Event

The Event object represents an event. Properties of the Event Object is listed in the following table. PropertyDescription dataArray of URL's for dragged and dropped objects heightHeight of window layerXHorizontal cursor position within layer layerYVertical cursor position within layer modifiersBit mask representing modifier keys pageXHorizontal cursor position within Web page pageYVertical cursor position within Web page screenXHorizontal cursor position within computer screen screenYVertical cursor position within computer screen targetObject for captured events typeType of event whichThe mouse button that is pressed widthWidth of window In addition to the Event properties, events exist that get handled. The available events are shown in the following Table. EventsDescription ABORTLoading of Web page interrupted by user. BLURFocus is removed from the object. CHANGEContents or setting for document object changed. CLICKMouse button is clicked once. DBLCLICKMouse button is clicked twice. DRAGDROPObject is dragged and dropped. ERRORError occurred during loading. FOCUSFocus is applied to an object. KEYDOWNA key is pressed down. KEYPRESSA key is pressed. KEYUPA key is let up after being pressed down. LOADLoad document within a browser. MOUSEDOWNThe mouse button is pressed down. MOUSEMOVEThe mouse cursor is moved. MOUSEOUTThe mouse cursor is moved away from a specific object. MOUSEOVERThe mouse cursor is moved over a specific object. MOUSEUPThe pressed mouse button is let up. MOVEObject is moved on the screen. RESETReset button is pressed. RESIZEWindow or frame has been resized. SELECTDocument object is selected. SUBMITSubmit button is pressed. UNLOADDocument is unloaded from browser. <html>     <head>     <title>Using the event object</title>     </head>     <body>     <script language = "Javascript">     <!--     window.captureEvents(Event.KEYPRESS | Event.DBLCLICK);     document.captureEvents(Event.SUBMIT);     function handlePress(evnt){        alert("You pressed a key down. The event type: " + evnt.type);        return true;     }     function handleDblClick(evnt){        alert("You double clicked at location: " + evnt.pageX + "," + evnt.pageY);        return(true);     }     function handleSubmit(evnt){        alert("You clicked on the submit button");     }     window.onkeypress = handlePress;     window.ondblclick = handleDblClick;     document.onsubmit = handleSubmit;     -->     </script>     When you click on the submit button, it triggers the <b>SUBMIT</b>     event which displays an alert box.     <br><br>     If you double click somewhere in the page, it triggers the     <b>DBLCLICK</b> event.     <br><br>     When a key is pressed down in the browser, the <b>KEYPRESS</b>     event is triggered.     <br><br><br>     <form>     <input type="submit" value="Submit" onSubmit=''>     </form>     </body>     </html>