Name
Input.onclick: event handler invoked when a form element is clicked â DOM Level 2 Events
Synopsis
Function onclick
Description
The onclick
property of an
Input object specifies an event-handler function that is invoked
when the user activates the input element. This is typically done by
clicking the element with the mouse, but the onclick
handler is also triggered when the
user activates the element using keyboard traversal. The onclick
handler is also invoked when the
click( )
method is called for the
element.
Note that the input elements of type âresetâ and âsubmitâ
perform a default action when clicked: they reset and submit,
respectively, the form that contains them. You can use the onclick
event handlers of each element to
perform actions in addition to these default actions. You can also
prevent these default actions by returning false
or by using the other
event-cancellation techniques described in Chapter 17. Note that you can do similar things
with the onsubmit
and onreset
event handlers of the Form object
itself.
See Also
Element.addEventListener(
)
; Chapter 17
Get JavaScript: The Definitive Guide, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.