Полезная информация

JavaScript: The Definitive Guide

Previous Chapter 21
JavaScript Reference
Next
 

Element.onclick() Handler

Name

Element.onclick() Handler---invoked when a form element is clicked

Availability

Navigator 2.0, Internet Explorer 3.0; enhanced in Navigator 3.0

Synopsis

element.onclick

Description

The onclick() event handler of a form element is invoked by the web browser when the user clicks on the element. Note, however, that it is not invoked when JavaScript calls the click() method of an element.

The onclick() event handler is a function defined through the onClick attribute of the HTML tag that defined the form element. The value of this attribute is a string that may contain any number of JavaScript statements, separated by semicolons. In Navigator 3.0, the onclick() event handler may also be defined by assigning a function directly to the onclick property of an element.

Only form elements that are buttons invoke the onclick() event handler. These are the Button, Checkbox, Radio, Reset and Submit elements. Other form elements use the onchange() event handler instead of onclick().

Note that the Reset and Submit elements perform a default action when clicked: they reset and submit, respectively, the form that they are a part of. You can use the onclick() event handlers of each of these elements to perform actions in addition to these default actions. In Navigator 3.0, you can also prevent these default actions from occurring by returning false. That is, if the onclick() handler of a Reset button returns false, then the form will not be reset, and if the onclick() handler of a Submit button returns false, then the form will not be submitted. Note that you do similar things with the onsubmit() and onreset() event handlers of the Form object itself.

Finally, note that Link object also defines an onclick() event handler.

See Also

"Element", "Element.onblur()", "Element.onchange()", "Element.onfocus()"


Previous Home Next
Element.onchange() Book Index Element.onfocus()

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell