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 3 of 3

Thread: js user form

  1. #1
    New to the CF scene
    Join Date
    Mar 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    js user form

    I'm very new to web design and need help with a local website for a class project.

    I need a user to enter their name into a form, then the users name needs to appear somewhere on screen saying "Welcome 'user' " and if the form isn't filled, guest to appear instead.

    The name must appear on each other page on the site.

    Thanks!

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,302
    Thanks
    203
    Thanked 2,562 Times in 2,540 Posts
    Quote Originally Posted by connorav View Post
    I'm very new to web design and need help with a local website for a class project.

    I need a user to enter their name into a form, then the users name needs to appear somewhere on screen saying "Welcome 'user' " and if the form isn't filled, guest to appear instead.

    The name must appear on each other page on the site.

    Thanks!
    We will not do your homework for you, but if you write some code yourself I am sure that someone will help you correct/improve it.

    To make the user name appear on other pages you will need to use a query string, a cookie or local storage. These topics are a bit advanced for someone very new to Javascript.

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    Last edited by Philip M; 03-31-2014 at 06:52 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New to the CF scene
    Join Date
    Jan 2013
    Location
    Victoria, Australia
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    As a guide on some good places to start you can look at JavaScript Cookies for information on how to work with cookies. A basic guide would be to add an input field and a form button. When the form button is pressed a cookie should be saved with the value containing what was in the input field. Then on each page that needs to show the username you would need an if statement to check for the existence of the username cookie, if the cookie doesn't exist or if the cookie contains a blank value then the appropriate section should say "guest" otherwise the appropriate section should say the value of the cookie.


  •  

    Posting Permissions

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