asp.net.ph

Skip Navigation Links

onclick Event


Fires when the user clicks the left mouse button on the object.

Syntax

Inline <element onclick = "handler" ... >
Script object.onclick = handler

Remarks

Bubbles Yes
Cancels Yes
To invoke
  • Click the object.
  • Invoke the click method.
  • Press ENTER in a form.
  • Press the access key for a control.
  • Select an item in a combo box or list box by clicking the left mouse button or by pressing the arrow keys and then pressing the ENTER key.
Default action Initiates any action associated with the object. For example, clicking an A object causes the browser to load the document specified by the href property. To cancel the default behavior, set the returnValue property of the event object to FALSE.

A click event occurs when the pointing device button is clicked over an element. A click is defined as a mousedown and mouseup over the same screen location. The sequence of these events is: mousedown, mouseup, click.

For example, if the user clicks the left mouse button, the onclick event for an object occurs only if the mouse pointer is over the object and both an onmousedown and an onmouseup event occur in order. if the user presses down in the object but moves the mouse pointer out of the object before releasing, no onclick event occurs.

The onclick event changes the value of a control in a group. This change initiates the event for the group, not for the individual control. For example, if the user clicks a radio button or check box in a group, the onclick event occurs after the onbeforeupdate and onafterupdate events for the control group.

If the user clicks an object that can receive the input focus but does not already have the focus, the onfocus event occurs for that object before the onclick event. If the user double-clicks the left mouse button in a control, an ondblclick event occurs immediately after the onclick event.

Although the onclick event is available on a large number of HTML elements, if a Web page is to be accesible to keyboard users, its use should be restricted to the A, INPUT, AREA, and BUTTON elements. These elements automatically allow keyboard access through the TAB key, making Web pages that use them accessible to keyboard users.

Event Object Properties

While event handlers in the Document Object Model do not receive parameters directly, the handler can query the event object for data.

Event Object Properties


Example

The following examples demonstrate use of how the onclick event may be handled.

This example uses the event to trigger a function that detects the contents of the textbox and displays it in a dialog box.

 Show me 

This example uses the event object to gain information about the origin of the click, and cancels the default action if the onclick event is fired off an anchor.

Sample Code

 Show me 

This example shows how to bind the onclick event to grouped controls.

Sample Code

 Show me 

See Also

click, ondblclick


Need a break ?
Suggested Reading

Check out related books at Amazon

© 2025 Reynald Nuñez and asp.net.ph.

If you have any question, comment or suggestion,
please send us a note