Writing for the World Wide Web
Personalized Greeting
Well, , let's face it: the internet is a pretty big place, and sometimes it can seem a little unfriendly. Am I right, ? Yeah, I thought so. Well, there are ways you can personalize webpages a bit so people don't feel so alienated by the vastness of the internet. Pay attention, , because this script is a little trickier.

First, you need to find out what the person's name is, and you have to do this before your webpage loads. Until now, the head of the HTML document has been for titles only. Placing a JavaScript function in the head of your document will make it run before your webpage loads; this way, you can get information from your user to actually display in your webpage. Now we're going to add a script into the head of our HTML document so our head will look like this:

<head>
<title>What's Your Name?</title>
<script language="JavaScript">var user = prompt("Enter your name here:",'???');</script>
</head>

Here is a basic breakdown of what each part means:

  • var—declares the next word as a variable; a variable is a just like a variable in math class, where you can place any information you want in here, and what you place in this variable will affect the outcome of the function
  • user—the name I chose to use as a variable
  • prompt—a function that pops up a window asking the user for information; in this case, a name
  • "Enter your name here:"—this first message, in double quotes, is what is displayed in the alert window as the message
  • '???'—this second message, in single quotes, gets displayed in the input field of the alert window
  •  , —the comma separates the two bits of information
Now you have to find a place in your webpage to display the person's name. Anyplace in your HTML document where you want the user's name to appear, place the following code:

<script language="JavaScript">document.write(user);</script>

And you saw what the effects of this script were when you loaded this page. Hope you enjoy this one, ...


Home | Course Information | Assignments | Schedule | Class Notes | Resources | Student Pages