HTML and CSS Reference
In-Depth Information
The events, in their simplest form, are tied to HTML. In the following example, an
HTML form is created with the
<form>
tag and its attributes. Along with the
type
and
value
attributes, the JavaScript
onClick
event handler is just another attribute of the
HTML
<form>
tag. The type of input device is called a
button
and the value assigned to
the button is
“Pinch me”
. When the user clicks the button in the browser window, a Java-
Script event, called
click
, will be triggered. The
onClick
event handler is assigned a value
that is the command that will be executed after the button has been clicked. In our
example, it will result in an alert box popping up in its own little window, displaying
“
OUCH!!
”. See the output of Example 1.2 in Figures 1.6 and 1.7.
EXAMPLE
1.2
<html>
<head><title>Event</title></head>
<body>
1
<form>
2
<input type ="button"
3
value = "Pinch me"
4
onClick="alert('OUCH!!')"
/>
5
</form>
</body>
</html>
Figure 1.6
User initiates a click event when he or she clicks the mouse on the button.
Figure 1.7
The
onClick
event handler is triggered when the button labeled “Pinch me” is
pressed.