HTML and CSS Reference
In-Depth Information
Figure 13.25 After the user checks out, the PHP script processes the input data
from the form.
13.6.7 HTML Event Handlers and JavaScript Event Methods
You'll find that many JavaScript programs use a combination of event handlers and event
methods, especially when working with forms. Example 13.19 uses event handlers and
event methods. It creates a random number between 1 and 10, and asks the user to guess
what the number is. As soon as the document is loaded, the onLoad event handler is trig-
gered, and when the user clicks the button, the onClick handler is fired up. The focus()
method is used to put focus in the textbox where the user will enter his or her guess.
EXAMPLE 13.19
<html>
<head><title>Event Handling</title>
<script type="text/javascript">
var tries=0;
1
function randomize(){
// Random number is set when the document has loaded
var now=new Date();
num=(now.getSeconds())%10;
// modulus-remainder after division
num++;
}
2
function guessit(form){
// Function is called each time the user clicks the button
if (form.tfield.value == num){
alert("Correct!!");
3
form.tfield.focus();
n=0;
randomize();
}
 
 
Search WWH ::




Custom Search