View Full Version : Display "Welcome *Name*" on each page of site
05-28-2006, 10:09 AM
Is there any way to get what you type in to the prompt box below (a pseudo "username")to display on each page of a website after you submit it? I've done quite a lot of research, but I can't seem to find out how to do it. Of course, I may have been looking in all the wrong places, which might explain it *sweatdrop*
What I really would have liked is a password retrieval system, as I put in another thread, but my site isn't going to be on the net for a long time, so this will have to do. And I really don't have a members only area, so this option would be useless.
Anyway, the script!
name = window.prompt('Please enter your username: ','');
document.write('Welcome, '+name+ ' !');
P.s. I've run a search and found nothing on this forum... hope this hasn't been posted before.
05-28-2006, 10:34 AM
'name' is not a reserved word for a variable but it can cause problems in some situations - suggest you change it to usrname.
To achieve what you want you must set a cookie and then retrieve it for each page.
There are other many examples of this - try:-
05-28-2006, 10:50 AM
Thanks for the heads up! :thumbsup:
05-28-2006, 10:59 AM
Can this work without using a URL as a page destination? If so, what do I put?
05-28-2006, 01:07 PM
Can what work?
05-28-2006, 01:15 PM
This script. I have tried it without setting the page destination to a URL, but it doesn't work. Is there a way to test it without using a server? The pages are not yet on the interent, and i have a feeling that's where I'm going wrong.
The pages you kindly linked to didn't provide much help with making a cookie that sends the "Username" to each page to display, though I did learn some handy tips. Is there a cookie that does this, please?
Also, usrname did not work. Thanks very much anyway :)
05-28-2006, 03:28 PM
I have the feeling that you are way out of your depth and are trying in effect to learn to swim by correspondence course. However clear the instructions you still drown.
The idea is that you set the cookie on the index page (or the one where you ask the visitor to enter his username), and then read the cookie back ON EVERY SEPARATE PAGE where you want it to say "Hello UserName".
Of course usrname will work if you change each instance of 'name' to 'usrname'.
http://www.webreference.com/js/column8/name.html spells out very clearly how to set and retrieve a cookie containing the UserName. If you cannot follow (and copy) that then the whole subject is just too advanced for you at this stage.
05-28-2006, 07:13 PM
Thanks Philip M.
Should have realised that before making a fool of myself.
Thankyou for your patience.
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.