mercredi 17 avril 2019

How to store all checked items from a list into the local storage. (Javascript)

I have a list whit a dynamically created checkbox inputs and when the list is done and you finish using it, I want to store the checked items from the list to the localstorage.

HTML: ...

(also y have a kind of dialog where you create the new checkbox items and appends them to the list) ...

Js:

function add_checkbox_item(){

var product = document.getElementById('addirp').value;
var text_product = document.createTextNode(product);
var checkbox_product = document.createElement('ons-checkbox')
checkbox_product.appendChild(text_product);
var finall_product = document.createElement('ons-list-item');
finall_product.appendChild(checkbox_product);
    finall_product.classList.add("products");

document.getElementById('productos').appendChild(finall_product);

    dialog = document.getElementById('dialog1'); 
dialog.hide();  

}; 

function savefunction(){ HERE IS WHERE I START GETTING LOST

var checkedValue = null; 
var inputElements = document.getElementsByClassName('products');
for(var i=0; inputElements[i]; ++i){
  if(inputElements[i].checked){
       checkedValue = inputElements[i].value;
       break;


  }}}




Aucun commentaire:

Enregistrer un commentaire