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 6 of 6
  1. #1
    New Coder
    Join Date
    Feb 2010
    Posts
    30
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question Save Every User Input Using Cookies

    I need help using javascript cookies to save the input users will fill in to many inputs within one form. I've never worked with cookies and I was wondering if someone could help me out here - the answers I've found searching the web do not work for me.
    Any help is appreciated,
    Thanks.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,536
    Thanks
    80
    Thanked 4,490 Times in 4,454 Posts
    One caution: You are only allowed 4000 bytes of cookies per domain. If you have a *LOT* of <form> input to save, cookies aren't going to work.

    I assume the purpose of this is to handle multi-page <form>s, no? If so, you might be better of just copying the fields from the first page into hidden fields in the second page, etc.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Feb 2010
    Posts
    30
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Yes, I will have multiple pages with a form on each, and within each form, there will be like 20 text inputs. I want what the user inputs in each text input to be saved when closed, so when they return to that page, it will return to be in the boxes. Is this possible? If not with cookies, is there another way?

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,536
    Thanks
    80
    Thanked 4,490 Times in 4,454 Posts
    It's possible with cookies, but see the limitation I noted.

    It's also possible with the newer browsers using HTML5 to use something called "localStorage" There the recommended (but not mandatory) space per domain is 5 megabytes. Surely plenty big enough for what you are doing.

    If you don't mind restricting the use of your web page(s) to those browsers that support localStorage, it's probably your most practical answer.

    Here, read this:
    http://www.w3schools.com/html5/html5_webstorage.asp
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,146
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    Quote Originally Posted by Old Pedant View Post
    It's possible with cookies, but see the limitation I noted.

    It's also possible with the newer browsers using HTML5 to use something called "localStorage" There the recommended (but not mandatory) space per domain is 5 megabytes. Surely plenty big enough for what you are doing.

    If you don't mind restricting the use of your web page(s) to those browsers that support localStorage, it's probably your most practical answer.

    Here, read this:
    http://www.w3schools.com/html5/html5_webstorage.asp
    Remember one thing though, since this is client-side, the data stored will be on a per browser basis. If a user switches between IE and Firefox, it won’t use the same database. Same if they use your app on one machine and go to another somewhere else, that data will only be available on the machine it was created/saved on.

    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.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,536
    Thanks
    80
    Thanked 4,490 Times in 4,454 Posts
    Yes, Philip is quite right, of course. If you want true flexibility, the best thing to do is use server-side code (PHP/ASP/JSP) for this kind of thing.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Tags for this Thread

    Posting Permissions

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