JavaScript » eventhandler » onClick

Syntax:
onClick = myJavaScriptCode

Event handler for Button, Document, Checkbox, Link, Radio, Reset, Submit.

The onClick event handler executes the specified JavaScript code or function on the occurance of a click event. When used with checkboxes, links, radio, reset and submit buttons, onClick can return a false value which cancels the normal action associated with the click event. With form objects that have default actions this works as follows:

Radio buttons and checkboxes - nothing is set
Submit buttons - submission of the form is cancelled.
Reset buttons - resetting of the form is cancelled.

The onClick event handler uses the following Event object properties.

type - this property indicates the type of event.
target - this property indicates the object to which the event was originally sent.
*layerX - the cursor location when the click event occurs.
*layerY - the cursor location when the click event occurs.
*pageX - the cursor location when the click event occurs.
*pageY - the cursor location when the click event occurs.
*screenX - the cursor location when the click event occurs.
*screenY - the cursor location when the click event occurs.
which - 1 represents a left mouse click and 3 a right click.
modifiers - lists the modifier keys (shift, alt, ctrl, etc.) held down when the click event occurs.

*when a link is clicked.

Examples

Code:
<INPUT TYPE="RESET" onClick="return confirm('Are you sure?')">
Explanation:

This example shows the use of the onClick event handler to offer users the chance to cancel the resetting of a from when clicking on a Reset button.

See Also: