View Full Version : A basic name prompt

10-11-2003, 05:12 AM
I am currently learning Javascript from one of your recommended sites as a tutorial. Concerning the example of a name prompt from http://home.cogeco.ca/~ve3ll/jstutor1.htm#temp , I had a question. Is there a way I could use that prompt (or any other) to get someone to type their name in, and then have it inserted into a marquee along with a little bit of other text?

--For example: If I wanted someone named John to type their name in, I'd want the page's marquee to display "Welcome to my site, John!"
-I'm new, so I would definitely appreciate any help or comments. Thanks! :thumbsup:

10-11-2003, 05:30 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=iso-8859-1" />
<script type="text/javascript">
var user, marquee;

function init()
user = window.prompt("Name: ", "");
user = (user) ? user : 'Guest';

marquee = document.createElement("marquee");
marquee.setAttribute("style", "color: #0000ff; font-family: helvetica, serif; font-size: 20pt;");
marquee.innerHTML = "Welcome to my site, " + user + "!";

document.body.appendChild( marquee );

onload = init;


10-11-2003, 06:25 AM
wow that was quick Fred, thank you :p

10-11-2003, 06:26 AM
You're welcome. :D

10-11-2003, 04:34 PM
Doesn't that create a <marquee> tag? There are better ways of doing that, as marquee is depreciated ;)

10-12-2003, 03:19 PM
Any other ways would be helpful as well, but until then I'll just stick with Fred's way. :D Go fred