Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Display "Welcome *Name*" on each page of site

    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!

    <html>
    <title></title>
    <head>
    <script language="JavaScript">

    name="";
    name = window.prompt('Please enter your username: ','');
    document.write('Welcome, '+name+ ' !');
    </script>

    </script>
    </head>
    <body>
    </body>
    </html>

    Thanks!

    P.s. I've run a search and found nothing on this forum... hope this hasn't been posted before.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    '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.
    See:-

    http://www.webreference.com/js/column8/name.html

    http://www.w3schools.com/js/js_cookies.asp

    There are other many examples of this - try:-

    http://javascript.internet.com/cookies/n-browser.html
    or
    http://www.paulspages.co.uk/pcp/cookielib/index.htm

    Note that if you had used Google and typed in 'javascript username cookie' you would have found all of the above right away.
    Last edited by Philip M; 05-28-2006 at 09:41 AM.

  • #3
    New to the CF scene
    Join Date
    May 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the heads up!

  • #4
    New to the CF scene
    Join Date
    May 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can this work without using a URL as a page destination? If so, what do I put?

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Can what work?

  • #6
    New to the CF scene
    Join Date
    May 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    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.

    To try to answer your other question, JavaScript is a client-side language and thus will work on the local machine regardless of whether you are connected to a server or not.
    Last edited by Philip M; 05-28-2006 at 02:35 PM.

  • #8
    New to the CF scene
    Join Date
    May 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Philip M.

    I am way out of my league at this point in time. I have been learning JavaScript for a grand total of 3 days now. I still have no idea what anything does at this point.

    Should have realised that before making a fool of myself.

    Thankyou for your patience.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •