To create a dynamic welcome page that obtains the user's name, then diplays it on the page. The script uses another predefined dialog box from window object(a prompt dialog) which allows the user to input a value that the script can use. The program asks the user to input a name, then displays the name in the XHTML document.
A declaration that contains the JavaScript keyword var. Keywords are words that have special meaning in JavaScript. The keyword var at the beginning of the statement indicates that the word name is a variable. A variable is a location in the computer's memory where a value can be stored for use by a program.
<html>
<head>
<title>Using Prompt and Alert Boxes</title>
<script type = "text/javascript">
<!--
var name; //string entered by the user
name = window.prompt( "Please enter your name" );
document.writeln( "<h1> Hello, " + name + ",
welcome to JavaScript programming!</h1>" );
// -->
</script>
</head>
<body>
<p>Click Refresh to run this script again.</p>
</body>
</html>
<head>
<title>Using Prompt and Alert Boxes</title>
<script type = "text/javascript">
<!--
var name; //string entered by the user
name = window.prompt( "Please enter your name" );
document.writeln( "<h1> Hello, " + name + ",
welcome to JavaScript programming!</h1>" );
// -->
</script>
</head>
<body>
<p>Click Refresh to run this script again.</p>
</body>
</html>
A declaration that contains the JavaScript keyword var. Keywords are words that have special meaning in JavaScript. The keyword var at the beginning of the statement indicates that the word name is a variable. A variable is a location in the computer's memory where a value can be stored for use by a program.