Buy online at www.borders.com

It's Not Just Help. . .

So How Does It Work?

HTML Topics & Templates
CSS
DHTML
Project File (.hhp)

Contents File (.hhc)

Merging Modular Files

Accelerating Links

Distribution & Installation



HTML Help Resources on the Web


Alert Message Using Input
from a Prompt Recipe

Purpose

This recipe opens a prompt dialog asking the user for information, then uses that information to customize an alert message.

Sample

Click here to test your knowledge.

Erratum

In the function as printed on p. 218, there is a closing parentheses missing after "desiredMessage". The line should read:
{alert("desiredMessage")}

The full correct function is shown below.

Function

<SCRIPT LANGUAGE="JavaScript">
function test()
{
var foo=prompt("Question?", "defaultResponse")
if(foo=="desiredResponse")
{alert("desiredMessage")}
else
{alert("alternateMessage")}
}
</SCRIPT>

where

 

foo

is a variable used to access the name property of the graphic or other element modified by the functions.

 

Question

is the question the prompt box poses to the user;

 

defaultResponse

is the answer used if the user does not respond to the Question;

 

desiredResponse

is the correct or preferred answer to the Question;

 

desiredMessage

is the computer response to the correct or preferred answer (the desiredResponse);

 

alternateMessage

is the computer response to any answer other than the one specified as correct or preferred.

Call within the element

<P onClick="test()">Click here to test your knowledge.</P>

Possible modifications

In the chapter, this example was used in a primitive passwording scheme that greeted an approved user by name. It could also be used in a multiple-choice quiz situation to give reinforcement for correct answers (“Good job!”) or ask the user to “Try again.”