Results 1 to 3 of 3

Thread: Any (simple) way with JS to use localstorage to remember entries in all text boxes?

  1. #1
    Join Date
    May 2014
    Posts
    27
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Default Any (simple) way with JS to use localstorage to remember entries in all text boxes?

    Hi, I am working on a quiz page which will have lots (probably 1000) text boxes to enter answers to, ideally I like to make it possible for user to refresh or leave page and return without losing progress... I have worked out by googling some examples how to do it with localstorage, but only with unique IDs for each text box... Is there anyway of targeting all text boxes? The examples I've found seem to reference each individually but uniquely listing 1000 different ones is a pain in the ass if there is another way.

    Many thanks to anyone who may be able to help
    Last edited by Neil1; 04-26-2017 at 07:27 PM.

  2. #2
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,725
    Thanks
    46
    Thanked 214 Times in 207 Posts
    Blog Entries
    52

    Default

    Localstorage should be possible with document.querySelectorAll (instead of document.getElementById). Have you tried that?

  3. The Following User Says Thank You to molendijk For This Useful Post:

    Neil1 (05-02-2017)

  4. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,256
    Thanks
    75
    Thanked 3,395 Times in 3,356 Posts
    Blog Entries
    12

    Default

    One thing to bear in mind with localStorage is that, if it's not enabled in the user's browser, it can cause a fatal error when code goes to use it. Because of that I tend to rely upon cookies for this sort of thing. I've read that a try/catch can be used to avoid the error inherent in (at least Chrome style) browsers, but I've yet to test that theory and do know that Chrome barfs (gives a fatal error) on localStorage if it's not enabled and not in a try/catch. That doesn't mean try/catch will work for avoiding that though.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. The Following User Says Thank You to jscheuer1 For This Useful Post:

    Neil1 (05-02-2017)

Similar Threads

  1. Simple question with select boxes.
    By d0pes1ck in forum PHP
    Replies: 2
    Last Post: 02-10-2010, 12:47 PM
  2. how to make pop up text boxes?
    By 3220796chad in forum HTML
    Replies: 0
    Last Post: 07-11-2006, 12:52 AM
  3. Replies: 1
    Last Post: 12-16-2005, 09:15 PM
  4. Text Boxes
    By Freeman in forum CSS
    Replies: 2
    Last Post: 10-26-2005, 03:42 PM
  5. Text Boxes
    By Freeman in forum HTML
    Replies: 0
    Last Post: 10-25-2005, 03:47 PM

Bookmarks

Posting Permissions

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