Jack Nilan         Javascript Tutorial        EMail : jacknilan@yahoo.com



Lesson 8 -Prompting and Responding to Input

You can prompt users for input using the built in dialogue box.

The following script when entered into the head of your document will prompt the user for input and then redirect them to visit a certain web page based on their name. In this way you can give people a certain code and then redirect them to a page that is only accessible to them.

<script>
var person = prompt("What is your name?", "");
document.write("< h1>Custom page for " + person + "< /h1>");
if (person == "Jack")
{
document.write("<p>");
document.write("<a href='http://jacknilan.com'>");
document.write("Visit Mr. Nilan's web site.");
document.write("</a></p>");
}
else if (person =="Sue")
{
document.write("< p><");
document.write("<a href='http://google.com'>");
document.write("Search on Google.");
document.write("</a>< /p>");
}
</script>

The script will be executed as soon as the web page is opened. Your assignment is to print a certain message to the screen based on the name that the person enters. Have at least 3 names that personalized messages will be written for.