Event : Event Object « Event « JavaScript Tutorial






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>








15.1.Event Object
15.1.1.Event
15.1.2.event.data
15.1.3.event.height
15.1.4.event.layerX
15.1.5.event.layerY
15.1.6.event.pageX
15.1.7.event.pageY
15.1.8.event.screenX
15.1.9.event.screenY
15.1.10.event.target
15.1.11.event.type
15.1.12.event.which
15.1.13.event.width
15.1.14.Event.ABORT
15.1.15.Event.CHANGE
15.1.16.Add event handler to form