Button.onClick

JavaScript 1.0+, JScript 1.0+ Nav2+, IE 3+ Syntax

onClick="command"

Description

The onClick event handler is defined in an <input> tag and specifies what to do when the button is clicked.

Example

The code in Listing 7.29 uses the onClick event handler to display an alert box any time the button is clicked.

Listing 7.29 Use onClick Event Handler to Display an Alert Box When the Button Is Clicked
<html>

<form name="myForm">
  <input type="button"
         value="Big Button"
         name="myButton"
         onClick="alert('Click event occurred')">
</form>

</html>
							
						

Get Pure JavaScript 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.