HTML and CSS Reference
In-Depth Information
EXAMPLE 4.4 ( CONTINUED )
<body>
<script type="text/javascript">
1
if(confirm("Are you really OK?") == true){
2
alert("Then we can proceed!");
}
else{
3
alert("We'll try when you feel better? ");
}
</script>
</body>
</html>
EXPLANATION
1
The confirm dialog box takes only one argument, the question that you want to
ask the user. It returns true if the user clicks the OK button and false if the user
clicks the Cancel button. He or she has to click either one to continue. If the re-
turn value is equal to true , then the alert() method on line 2 will be executed. The
if/else constructs are not discussed until Chapter 6, “Under Certain Conditions,”
but the way they are used here is to test a true or false alternative to make the ex-
ample a little more meaningful.
2
The user clicked OK. The alert dialog box will display its message (see Figure 4.7).
3
If the user clicked Cancel, this alert dialog box will display its message (see
Figure 4.7).
Figure 4.5 The confirm dialog box (Firefox).
Search WWH ::




Custom Search