-2

where is going wrong to set localstorage book item? html:

<li id="pitaka_confic">Set the book list in main interface </li>
          <input class="pitaka" type="radio" name="pitaka" value="pali" checked="checked"> Hindi
          <input class="pitaka" type="radio" name="pitaka" value="bengali">Bengali
          <input class="pitaka" type="radio" name="pitaka" value="english">English  

javascript:

var radios = document.querySelectorAll('.book')
     for(var i = 0; i < radio.length; i++){
          var val = radios[i].value
          radios[i].addEventListener('click',()=>{
            localStorage.setItem('bookid', radios[i].value)
          })

        }
Tareng Chakma
  • 17
  • 1
  • 4

1 Answers1

1

Firstly, you don't have any items of class book. They are of class pitaka.

Secondly, you're using the same function all the time - so it'd be easier to simply do:

const function = event => localStorage.setItem("bookid", element.target.value);

And thirdly, you have var radios but you're using radio.length. Here's some refactored code:

const clickFunc = event => localStorage.setItem("bookid", event.target.value);

var radios = document.querySelectorAll(".pitaka");

for (let i = 0; i < radios.length; i++) {

    radios[i].addEventListener("click", clickFunc);

}
Jack Bashford
  • 43,180
  • 11
  • 50
  • 79