localStorage - Retrieve Checkbox ValuesGetting all selected checkboxes in an arrayGet the value of checked checkbox?Which “href” value should I use for JavaScript links, “#” or “javascript:void(0)”?Setting “checked” for a checkbox with jQuery?Set a default parameter value for a JavaScript functionHow can I get query string values in JavaScript?Sort array of objects by string property valueStoring Objects in HTML5 localStorageCheck if checkbox is checked with jQueryWhat is the max size of localStorage values?Copy array by valueClearing localStorage in javascript?

Personal Teleportation: From Rags to Riches

How could indestructible materials be used in power generation?

What does “the session was packed” mean in this context?

How much of data wrangling is a data scientist's job?

How would I stat a creature to be immune to everything but the Magic Missile spell? (just for fun)

How do I gain back my faith in my PhD degree?

Is it inappropriate for a student to attend their mentor's dissertation defense?

Is there a hemisphere-neutral way of specifying a season?

What reasons are there for a Capitalist to oppose a 100% inheritance tax?

Could the museum Saturn V's be refitted for one more flight?

What exploit Are these user agents trying to use?

What's the in-universe reasoning behind sorcerers needing material components?

How do I deal with an unproductive colleague in a small company?

How to show a landlord what we have in savings?

Watching something be piped to a file live with tail

Im going to France and my passport expires June 19th

Apex Framework / library for consuming REST services

Why is it a bad idea to hire a hitman to eliminate most corrupt politicians?

I would say: "You are another teacher", but she is a woman and I am a man

How to tell a function to use the default argument values?

How badly should I try to prevent a user from XSSing themselves?

Is it acceptable for a professor to tell male students to not think that they are smarter than female students?

Examples of smooth manifolds admitting inbetween one and a continuum of complex structures

How does a predictive coding aid in lossless compression?



localStorage - Retrieve Checkbox Values


Getting all selected checkboxes in an arrayGet the value of checked checkbox?Which “href” value should I use for JavaScript links, “#” or “javascript:void(0)”?Setting “checked” for a checkbox with jQuery?Set a default parameter value for a JavaScript functionHow can I get query string values in JavaScript?Sort array of objects by string property valueStoring Objects in HTML5 localStorageCheck if checkbox is checked with jQueryWhat is the max size of localStorage values?Copy array by valueClearing localStorage in javascript?













0















I'm working with a form (made with Bootstrap 4) and localStorage. I'm using it so i can use the form input values on another page. It works fine with the inputs, but in this form i also have checkboxes and i can't find how to do the following : i'd like to check which checkboxes are checked. For those that are checked, i'd like to add the checkbox label text in the localStorage to use it on my other page. How can i achieve this?



My html looks like this :



 <form role="form" id="form" data-toggle="validator">

<div class="form-row">
<div class="form-group col-md-12">
<label for="inputAdresse">Adresse *</label>
<input type="text" class="form-control places-autocomplete" name="inputAdresse" id="inputAdresse"
required="required" placeholder="" value="" autocomplete=" address-line1" />
</div>
</div>

<div class="form-row form-checks">
<div class="form-group col-md-12 col-sm-6">
<div class="custom-control custom-checkbox mb-2">
<input type="checkbox" class="custom-control-input" id="checkAscenseur" name="check" value="Ascenseur">
<label class="custom-control-label" for="checkAscenseur">Ascenseur</label>
</div>

<div class="custom-control custom-checkbox mb-2">
<input type="checkbox" class="custom-control-input" id="checkCave" name="check" value="Cave">
<label class="custom-control-label" for="checkCave">Cave</label>
</div>

<div class="custom-control custom-checkbox mb-2">
<input type="checkbox" class="custom-control-input" id="checkParking" name="check" value="Parking">
<label class="custom-control-label" for="checkParking">Parking</label>
</div>
</div>
</div>
<button class="nextBtn pull-right" type="submit" id="btn-submit">Submit</button>
</form>


For the input, i use the following javascript :



document.getElementById("form").addEventListener("submit", callme);

function callme(event)
event.preventDefault();

let inputAdresse = document.getElementById('inputAdresse');
localStorage.setItem('inputAdresse', inputAdresse.value);

window.location.href = "thank-you.html";
;









share|improve this question
























  • Possible duplicate of Getting all selected checkboxes in an array

    – APAD1
    Mar 21 at 21:32











  • See also Get the value of checked checkbox?

    – Benjamin
    Mar 21 at 21:34











  • I found these articles and tried to add var inputCheckboxes = new Array(); $("input:checkbox[name=check]:checked").each(function () inputCheckboxes.push($(this).val()); ); to my javascript. But i can't figure out how then to store them in localStorage and use them with getItem on the next page..

    – Alany
    Mar 21 at 21:43












  • @Alany Please check my answer below - it has a working demo of what you need: stackoverflow.com/a/55289712/3000684

    – Nadí
    Mar 21 at 21:48











  • @Nadi Yess i actually had to cleanup my localStorage, that's why this wan't working. Now i see them in the localStorage but this records true or false (Eg. checkAscenseur: "true"). How can i record the value of the checkbox instead?

    – Alany
    Mar 21 at 22:16















0















I'm working with a form (made with Bootstrap 4) and localStorage. I'm using it so i can use the form input values on another page. It works fine with the inputs, but in this form i also have checkboxes and i can't find how to do the following : i'd like to check which checkboxes are checked. For those that are checked, i'd like to add the checkbox label text in the localStorage to use it on my other page. How can i achieve this?



My html looks like this :



 <form role="form" id="form" data-toggle="validator">

<div class="form-row">
<div class="form-group col-md-12">
<label for="inputAdresse">Adresse *</label>
<input type="text" class="form-control places-autocomplete" name="inputAdresse" id="inputAdresse"
required="required" placeholder="" value="" autocomplete=" address-line1" />
</div>
</div>

<div class="form-row form-checks">
<div class="form-group col-md-12 col-sm-6">
<div class="custom-control custom-checkbox mb-2">
<input type="checkbox" class="custom-control-input" id="checkAscenseur" name="check" value="Ascenseur">
<label class="custom-control-label" for="checkAscenseur">Ascenseur</label>
</div>

<div class="custom-control custom-checkbox mb-2">
<input type="checkbox" class="custom-control-input" id="checkCave" name="check" value="Cave">
<label class="custom-control-label" for="checkCave">Cave</label>
</div>

<div class="custom-control custom-checkbox mb-2">
<input type="checkbox" class="custom-control-input" id="checkParking" name="check" value="Parking">
<label class="custom-control-label" for="checkParking">Parking</label>
</div>
</div>
</div>
<button class="nextBtn pull-right" type="submit" id="btn-submit">Submit</button>
</form>


For the input, i use the following javascript :



document.getElementById("form").addEventListener("submit", callme);

function callme(event)
event.preventDefault();

let inputAdresse = document.getElementById('inputAdresse');
localStorage.setItem('inputAdresse', inputAdresse.value);

window.location.href = "thank-you.html";
;









share|improve this question
























  • Possible duplicate of Getting all selected checkboxes in an array

    – APAD1
    Mar 21 at 21:32











  • See also Get the value of checked checkbox?

    – Benjamin
    Mar 21 at 21:34











  • I found these articles and tried to add var inputCheckboxes = new Array(); $("input:checkbox[name=check]:checked").each(function () inputCheckboxes.push($(this).val()); ); to my javascript. But i can't figure out how then to store them in localStorage and use them with getItem on the next page..

    – Alany
    Mar 21 at 21:43












  • @Alany Please check my answer below - it has a working demo of what you need: stackoverflow.com/a/55289712/3000684

    – Nadí
    Mar 21 at 21:48











  • @Nadi Yess i actually had to cleanup my localStorage, that's why this wan't working. Now i see them in the localStorage but this records true or false (Eg. checkAscenseur: "true"). How can i record the value of the checkbox instead?

    – Alany
    Mar 21 at 22:16













0












0








0








I'm working with a form (made with Bootstrap 4) and localStorage. I'm using it so i can use the form input values on another page. It works fine with the inputs, but in this form i also have checkboxes and i can't find how to do the following : i'd like to check which checkboxes are checked. For those that are checked, i'd like to add the checkbox label text in the localStorage to use it on my other page. How can i achieve this?



My html looks like this :



 <form role="form" id="form" data-toggle="validator">

<div class="form-row">
<div class="form-group col-md-12">
<label for="inputAdresse">Adresse *</label>
<input type="text" class="form-control places-autocomplete" name="inputAdresse" id="inputAdresse"
required="required" placeholder="" value="" autocomplete=" address-line1" />
</div>
</div>

<div class="form-row form-checks">
<div class="form-group col-md-12 col-sm-6">
<div class="custom-control custom-checkbox mb-2">
<input type="checkbox" class="custom-control-input" id="checkAscenseur" name="check" value="Ascenseur">
<label class="custom-control-label" for="checkAscenseur">Ascenseur</label>
</div>

<div class="custom-control custom-checkbox mb-2">
<input type="checkbox" class="custom-control-input" id="checkCave" name="check" value="Cave">
<label class="custom-control-label" for="checkCave">Cave</label>
</div>

<div class="custom-control custom-checkbox mb-2">
<input type="checkbox" class="custom-control-input" id="checkParking" name="check" value="Parking">
<label class="custom-control-label" for="checkParking">Parking</label>
</div>
</div>
</div>
<button class="nextBtn pull-right" type="submit" id="btn-submit">Submit</button>
</form>


For the input, i use the following javascript :



document.getElementById("form").addEventListener("submit", callme);

function callme(event)
event.preventDefault();

let inputAdresse = document.getElementById('inputAdresse');
localStorage.setItem('inputAdresse', inputAdresse.value);

window.location.href = "thank-you.html";
;









share|improve this question
















I'm working with a form (made with Bootstrap 4) and localStorage. I'm using it so i can use the form input values on another page. It works fine with the inputs, but in this form i also have checkboxes and i can't find how to do the following : i'd like to check which checkboxes are checked. For those that are checked, i'd like to add the checkbox label text in the localStorage to use it on my other page. How can i achieve this?



My html looks like this :



 <form role="form" id="form" data-toggle="validator">

<div class="form-row">
<div class="form-group col-md-12">
<label for="inputAdresse">Adresse *</label>
<input type="text" class="form-control places-autocomplete" name="inputAdresse" id="inputAdresse"
required="required" placeholder="" value="" autocomplete=" address-line1" />
</div>
</div>

<div class="form-row form-checks">
<div class="form-group col-md-12 col-sm-6">
<div class="custom-control custom-checkbox mb-2">
<input type="checkbox" class="custom-control-input" id="checkAscenseur" name="check" value="Ascenseur">
<label class="custom-control-label" for="checkAscenseur">Ascenseur</label>
</div>

<div class="custom-control custom-checkbox mb-2">
<input type="checkbox" class="custom-control-input" id="checkCave" name="check" value="Cave">
<label class="custom-control-label" for="checkCave">Cave</label>
</div>

<div class="custom-control custom-checkbox mb-2">
<input type="checkbox" class="custom-control-input" id="checkParking" name="check" value="Parking">
<label class="custom-control-label" for="checkParking">Parking</label>
</div>
</div>
</div>
<button class="nextBtn pull-right" type="submit" id="btn-submit">Submit</button>
</form>


For the input, i use the following javascript :



document.getElementById("form").addEventListener("submit", callme);

function callme(event)
event.preventDefault();

let inputAdresse = document.getElementById('inputAdresse');
localStorage.setItem('inputAdresse', inputAdresse.value);

window.location.href = "thank-you.html";
;






javascript local-storage






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 21 at 22:34







Alany

















asked Mar 21 at 21:28









AlanyAlany

195




195












  • Possible duplicate of Getting all selected checkboxes in an array

    – APAD1
    Mar 21 at 21:32











  • See also Get the value of checked checkbox?

    – Benjamin
    Mar 21 at 21:34











  • I found these articles and tried to add var inputCheckboxes = new Array(); $("input:checkbox[name=check]:checked").each(function () inputCheckboxes.push($(this).val()); ); to my javascript. But i can't figure out how then to store them in localStorage and use them with getItem on the next page..

    – Alany
    Mar 21 at 21:43












  • @Alany Please check my answer below - it has a working demo of what you need: stackoverflow.com/a/55289712/3000684

    – Nadí
    Mar 21 at 21:48











  • @Nadi Yess i actually had to cleanup my localStorage, that's why this wan't working. Now i see them in the localStorage but this records true or false (Eg. checkAscenseur: "true"). How can i record the value of the checkbox instead?

    – Alany
    Mar 21 at 22:16

















  • Possible duplicate of Getting all selected checkboxes in an array

    – APAD1
    Mar 21 at 21:32











  • See also Get the value of checked checkbox?

    – Benjamin
    Mar 21 at 21:34











  • I found these articles and tried to add var inputCheckboxes = new Array(); $("input:checkbox[name=check]:checked").each(function () inputCheckboxes.push($(this).val()); ); to my javascript. But i can't figure out how then to store them in localStorage and use them with getItem on the next page..

    – Alany
    Mar 21 at 21:43












  • @Alany Please check my answer below - it has a working demo of what you need: stackoverflow.com/a/55289712/3000684

    – Nadí
    Mar 21 at 21:48











  • @Nadi Yess i actually had to cleanup my localStorage, that's why this wan't working. Now i see them in the localStorage but this records true or false (Eg. checkAscenseur: "true"). How can i record the value of the checkbox instead?

    – Alany
    Mar 21 at 22:16
















Possible duplicate of Getting all selected checkboxes in an array

– APAD1
Mar 21 at 21:32





Possible duplicate of Getting all selected checkboxes in an array

– APAD1
Mar 21 at 21:32













See also Get the value of checked checkbox?

– Benjamin
Mar 21 at 21:34





See also Get the value of checked checkbox?

– Benjamin
Mar 21 at 21:34













I found these articles and tried to add var inputCheckboxes = new Array(); $("input:checkbox[name=check]:checked").each(function () inputCheckboxes.push($(this).val()); ); to my javascript. But i can't figure out how then to store them in localStorage and use them with getItem on the next page..

– Alany
Mar 21 at 21:43






I found these articles and tried to add var inputCheckboxes = new Array(); $("input:checkbox[name=check]:checked").each(function () inputCheckboxes.push($(this).val()); ); to my javascript. But i can't figure out how then to store them in localStorage and use them with getItem on the next page..

– Alany
Mar 21 at 21:43














@Alany Please check my answer below - it has a working demo of what you need: stackoverflow.com/a/55289712/3000684

– Nadí
Mar 21 at 21:48





@Alany Please check my answer below - it has a working demo of what you need: stackoverflow.com/a/55289712/3000684

– Nadí
Mar 21 at 21:48













@Nadi Yess i actually had to cleanup my localStorage, that's why this wan't working. Now i see them in the localStorage but this records true or false (Eg. checkAscenseur: "true"). How can i record the value of the checkbox instead?

– Alany
Mar 21 at 22:16





@Nadi Yess i actually had to cleanup my localStorage, that's why this wan't working. Now i see them in the localStorage but this records true or false (Eg. checkAscenseur: "true"). How can i record the value of the checkbox instead?

– Alany
Mar 21 at 22:16












2 Answers
2






active

oldest

votes


















1














Here is the working DEMO of how to do what you need.



You need to use the checked property for checkboxes:






document.getElementById("form").addEventListener("submit", callme);

function callme(event)
event.preventDefault();

let inputAdresse = document.getElementById('inputAdresse');
localStorage.setItem('inputAdresse', inputAdresse.value);

let checkAscenseur = document.getElementById('checkAscenseur');
localStorage.setItem('checkAscenseur', checkAscenseur.checked);

let checkCave = document.getElementById('checkCave');
localStorage.setItem('checkCave', checkCave.checked);

let checkParking = document.getElementById('checkParking');
localStorage.setItem('checkParking', checkParking.checked);

window.location.href = "thank-you.html";
;





UPD new code that saves data values instead of true/false: DEMO.






share|improve this answer
































    0














    You could also do it the following way (pretty much the same, but a bit more compact):



    document.getElementById("form").addEventListener("submit", callme);

    function callme(event)
    event.preventDefault();

    let inputAdresse = document.getElementById('inputAdresse');
    localStorage.setItem('inputAdresse', inputAdresse.value);

    new Array(...document.getElementById('form').getElementsByClassName('custom-control-input')).forEach(cb =>
    localStorage.setItem(cb.id, cb.checked);


    window.location.href = "thank-you.html";



    I convert the HTMLCollection I get from the .getElementsByClassName(...) function to an array, which I can iterate over using .forEach(). If you want to store the values by their ids, this works fine :P






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55289511%2flocalstorage-retrieve-checkbox-values%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      Here is the working DEMO of how to do what you need.



      You need to use the checked property for checkboxes:






      document.getElementById("form").addEventListener("submit", callme);

      function callme(event)
      event.preventDefault();

      let inputAdresse = document.getElementById('inputAdresse');
      localStorage.setItem('inputAdresse', inputAdresse.value);

      let checkAscenseur = document.getElementById('checkAscenseur');
      localStorage.setItem('checkAscenseur', checkAscenseur.checked);

      let checkCave = document.getElementById('checkCave');
      localStorage.setItem('checkCave', checkCave.checked);

      let checkParking = document.getElementById('checkParking');
      localStorage.setItem('checkParking', checkParking.checked);

      window.location.href = "thank-you.html";
      ;





      UPD new code that saves data values instead of true/false: DEMO.






      share|improve this answer





























        1














        Here is the working DEMO of how to do what you need.



        You need to use the checked property for checkboxes:






        document.getElementById("form").addEventListener("submit", callme);

        function callme(event)
        event.preventDefault();

        let inputAdresse = document.getElementById('inputAdresse');
        localStorage.setItem('inputAdresse', inputAdresse.value);

        let checkAscenseur = document.getElementById('checkAscenseur');
        localStorage.setItem('checkAscenseur', checkAscenseur.checked);

        let checkCave = document.getElementById('checkCave');
        localStorage.setItem('checkCave', checkCave.checked);

        let checkParking = document.getElementById('checkParking');
        localStorage.setItem('checkParking', checkParking.checked);

        window.location.href = "thank-you.html";
        ;





        UPD new code that saves data values instead of true/false: DEMO.






        share|improve this answer



























          1












          1








          1







          Here is the working DEMO of how to do what you need.



          You need to use the checked property for checkboxes:






          document.getElementById("form").addEventListener("submit", callme);

          function callme(event)
          event.preventDefault();

          let inputAdresse = document.getElementById('inputAdresse');
          localStorage.setItem('inputAdresse', inputAdresse.value);

          let checkAscenseur = document.getElementById('checkAscenseur');
          localStorage.setItem('checkAscenseur', checkAscenseur.checked);

          let checkCave = document.getElementById('checkCave');
          localStorage.setItem('checkCave', checkCave.checked);

          let checkParking = document.getElementById('checkParking');
          localStorage.setItem('checkParking', checkParking.checked);

          window.location.href = "thank-you.html";
          ;





          UPD new code that saves data values instead of true/false: DEMO.






          share|improve this answer















          Here is the working DEMO of how to do what you need.



          You need to use the checked property for checkboxes:






          document.getElementById("form").addEventListener("submit", callme);

          function callme(event)
          event.preventDefault();

          let inputAdresse = document.getElementById('inputAdresse');
          localStorage.setItem('inputAdresse', inputAdresse.value);

          let checkAscenseur = document.getElementById('checkAscenseur');
          localStorage.setItem('checkAscenseur', checkAscenseur.checked);

          let checkCave = document.getElementById('checkCave');
          localStorage.setItem('checkCave', checkCave.checked);

          let checkParking = document.getElementById('checkParking');
          localStorage.setItem('checkParking', checkParking.checked);

          window.location.href = "thank-you.html";
          ;





          UPD new code that saves data values instead of true/false: DEMO.






          document.getElementById("form").addEventListener("submit", callme);

          function callme(event)
          event.preventDefault();

          let inputAdresse = document.getElementById('inputAdresse');
          localStorage.setItem('inputAdresse', inputAdresse.value);

          let checkAscenseur = document.getElementById('checkAscenseur');
          localStorage.setItem('checkAscenseur', checkAscenseur.checked);

          let checkCave = document.getElementById('checkCave');
          localStorage.setItem('checkCave', checkCave.checked);

          let checkParking = document.getElementById('checkParking');
          localStorage.setItem('checkParking', checkParking.checked);

          window.location.href = "thank-you.html";
          ;





          document.getElementById("form").addEventListener("submit", callme);

          function callme(event)
          event.preventDefault();

          let inputAdresse = document.getElementById('inputAdresse');
          localStorage.setItem('inputAdresse', inputAdresse.value);

          let checkAscenseur = document.getElementById('checkAscenseur');
          localStorage.setItem('checkAscenseur', checkAscenseur.checked);

          let checkCave = document.getElementById('checkCave');
          localStorage.setItem('checkCave', checkCave.checked);

          let checkParking = document.getElementById('checkParking');
          localStorage.setItem('checkParking', checkParking.checked);

          window.location.href = "thank-you.html";
          ;






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 22 at 1:31

























          answered Mar 21 at 21:44









          NadíNadí

          464212




          464212























              0














              You could also do it the following way (pretty much the same, but a bit more compact):



              document.getElementById("form").addEventListener("submit", callme);

              function callme(event)
              event.preventDefault();

              let inputAdresse = document.getElementById('inputAdresse');
              localStorage.setItem('inputAdresse', inputAdresse.value);

              new Array(...document.getElementById('form').getElementsByClassName('custom-control-input')).forEach(cb =>
              localStorage.setItem(cb.id, cb.checked);


              window.location.href = "thank-you.html";



              I convert the HTMLCollection I get from the .getElementsByClassName(...) function to an array, which I can iterate over using .forEach(). If you want to store the values by their ids, this works fine :P






              share|improve this answer



























                0














                You could also do it the following way (pretty much the same, but a bit more compact):



                document.getElementById("form").addEventListener("submit", callme);

                function callme(event)
                event.preventDefault();

                let inputAdresse = document.getElementById('inputAdresse');
                localStorage.setItem('inputAdresse', inputAdresse.value);

                new Array(...document.getElementById('form').getElementsByClassName('custom-control-input')).forEach(cb =>
                localStorage.setItem(cb.id, cb.checked);


                window.location.href = "thank-you.html";



                I convert the HTMLCollection I get from the .getElementsByClassName(...) function to an array, which I can iterate over using .forEach(). If you want to store the values by their ids, this works fine :P






                share|improve this answer

























                  0












                  0








                  0







                  You could also do it the following way (pretty much the same, but a bit more compact):



                  document.getElementById("form").addEventListener("submit", callme);

                  function callme(event)
                  event.preventDefault();

                  let inputAdresse = document.getElementById('inputAdresse');
                  localStorage.setItem('inputAdresse', inputAdresse.value);

                  new Array(...document.getElementById('form').getElementsByClassName('custom-control-input')).forEach(cb =>
                  localStorage.setItem(cb.id, cb.checked);


                  window.location.href = "thank-you.html";



                  I convert the HTMLCollection I get from the .getElementsByClassName(...) function to an array, which I can iterate over using .forEach(). If you want to store the values by their ids, this works fine :P






                  share|improve this answer













                  You could also do it the following way (pretty much the same, but a bit more compact):



                  document.getElementById("form").addEventListener("submit", callme);

                  function callme(event)
                  event.preventDefault();

                  let inputAdresse = document.getElementById('inputAdresse');
                  localStorage.setItem('inputAdresse', inputAdresse.value);

                  new Array(...document.getElementById('form').getElementsByClassName('custom-control-input')).forEach(cb =>
                  localStorage.setItem(cb.id, cb.checked);


                  window.location.href = "thank-you.html";



                  I convert the HTMLCollection I get from the .getElementsByClassName(...) function to an array, which I can iterate over using .forEach(). If you want to store the values by their ids, this works fine :P







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 21 at 21:52









                  Matthias M.Matthias M.

                  11




                  11



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55289511%2flocalstorage-retrieve-checkbox-values%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                      Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript