Mass Media For The Individual
Katy Whitton Web Development Logo
 
 
Tutorials - JavaScript - Lesson 5 - The Prompt Command

This is an example of how you can attach a small amount of user interactivity to your sites. In this way it is possible to personalise pages for your users.

The code works by asking the user for their name, placing that name in a variable (a variable is simply a "name" that then has a value attached to it - in this case the users name.)  The example that you just saw is in the <head> of the page and then uses the document.write command to write the name into the page. You can also attach this to an alert box:

<html>
<head>
<script language="javaScript">
var readername=prompt('enter your name', '');
</script>
</head>

<body>

<a href="#" onClick="alert('Hello '+readername+' how are you?');>Click here to see the code at work</a>

</body>
</html>

Click here to see the code at work

See if you can figure out what the variable is in the above example. If not, then check out Tutorial 6 which is all about variables.

back
 
Tutorials

Customer Log-In
If you have purchased our software, enter your email address and password below to download it.