![]() ![]() ![]() ![]() |
![]() |
Chapter Six Alert, Prompt and Confirm Boxes |
JavaScript Messages to the User (Dialog Boxes) There are many times when you wish to prompt input from the visitor to your pages, or tell them that they've made a mistake, or to have them make a decision. For this purpose, you may make a call that causes a bell to sound and a dialog box to appear superimposed upon the present screen. The user may not proceed without responding to this dialog box in some fashion. There are three different kinds of dialog boxes you can cause to be displayed: |
The Alert box, which simply displays a message with an OK that the user must click to acknowledge having read it. alert(variable); variable is the literal string or variable you have set to a string, or a combination of both, displayed to the user. The user may only click an OK button to close the dialog box. You can call the alert(); using an onClick= call in a form's button specification, as shown in the following example: |
The Confirm box, which gives the user a Yes or No option. If Yes is clicked, something you specify happens, while No can trigger another action or nothing at all, as you specify. confirm(variable); variable is the literal string or variable you have set to a string, or a combination of both, displayed to the user. The user may click a Yes button or a No button to close the dialog box. You can call the confirm(); using an onClick= call in a form's pushbutton, as shown in the following example: |
The Prompt box, usually used when a form has been incompletely filled out, which accepts a direct correcting text entry from the user. You control what message is displayed in these dialog boxes, and where appropriate, what happens when they are responded to. prompt(variable1,variable2 ); variable1 is the literal string or variable you have set to a string, or a combination of both, displayed to the user. The user may type input into a form element in the dialog box, and click an OK button or a Cancel button to close the dialog box. variable2 is a default value you may specify to be displayed in the prompt box. Click Here to see this script. |