free hosting   image hosting   hosting reseller   online album   e-shop   famous people 
Free Website Templates
Free Installer

Using Prompt Boxes


A prompt box is simple to use, and handy for gaining information from the user.

This example, from CodeLifter , asks for the user's name.


Paste all of the code below into the body section of your page:

How It Works


Since the script is inserted into the body section, it needs to be formatted to look nice on the page.

In this example, the text is centered with a font size of 6 and colour white. This can be modified to suit.


The user input from the prompt is assigned to the variable whatName:
var whatName=prompt("Please type in your name:","");
The first parameter of the prompt, "Please type in your name:" , is whatever question you wish to ask the user.

The second parameter - in this example, a blank space designated by "" - is the default text you wish to appear in the prompt box's text window.


This information is then passed to the function doName , which formats the output.

First, a check is made to see that the input is neither null nor a blank space:
if ((whatName != "")&&(whatName !=null))
If legitimate text is entered, the output is Hello, sometext !

Otherwise, the output is simply Hello!

The message itself may also be modified as desired.


Try It Out

Open Prompt Test page





© 2001 CyberSchool