238
Creating Cool Web Sites with HTML, XHTML, and CSS
Table 11-1: Continued Event Name
Description
onload
The page completes loading in the browser
onmousedown
The user clicks the mouse button
onmouseup
The user releases the mouse button
onmouseout
The cursor moves away from the element
onmouseover
The cursor moves over the element
onmove
The window moves
onresize
The window is resized
onselect
User selects text in an input or textarea element
onunload
Opposite of onload; user leaves the page
The four events most commonly used with JavaScript are onclick, onmouseover, onmouseout, and onload. I explore how to utilize these four events later in this chapter.
Expressions Much more interesting than variable assignment statements (JavaScript instructions that assign a value to a specified variable) are expressions, which are the real building blocks of JavaScript. Expressions can evaluate to a Boolean (as in “if this condition is true, then . . .”) or can evaluate to a string or numeric expression. Table 11-2 takes a look at each of these expressions.
Table 11-2: Three Types of Expressions in JavaScript Expression
What It Evaluates To
x + y > z
Evaluates to a Boolean: either true or false
x + (2 x y)-3
Evaluates to a numeric value, the sum of these two variables
name + “ (given name)”
Appends the specified string to the end of the value of the string name
JavaScript simplifies working with strings, sequences of characters such as names, addresses, product codes, and URLs. You can build up strings of other values by using the + symbol, as shown here: var name = “Gareth”, name2 = “Ashley”; names = name + “ and “ + name2;
The resultant variable names is set to Gareth and Ashley.