Get User Name

This script allows you to ask the user for their name, and then write their name within the document.


<html>
<head>
<title>My Web Page</title>
<script language="JavaScript">
<!--
  //  Script:       Get Username
  //  Version:      1.1
  //  Last Updated: November 11th 1998
  //  Author:       Scott Brady
  //  Org:          HotSource HTML Help
  //  Email:        webmaster at sbrady dot com
  //  Website:      http://www.sbrady.com/hotsource/

var who = prompt("Please enter your name","");

// -->
</script>
</head>
<body>

<h2 align=center>Welcome<script language="JavaScript"> 
document.write(", " +who+ ", "); </script> to my webpage.</h2>

</body>
</html>

Notes:

  1. To ensure the code is copied correctly, please click here.

See it in action