samedi 28 septembre 2019

Variable not reassigning on checked value

Value of variable garageVal is not being updated on checkbox selection.

Since the default position of the checkbox is checked on the first selection, garageVal is 15000, but it does not change when a different value is selected.

The purpose of this section is to calculate an estimate on a house. garageVal is plugged into a calculator along with other variables to generate a final value.

HTML:

  <div class="garage-block">
      <input type="checkbox" class='g1' name='garage'/>1</label>
      <input type="checkbox" class='g2' name='garage'/>2</label>
      <input type="checkbox" class='g3' name='garage'/>3</label>
  </div>

JS:

    let g1 = document.querySelector('.g1');
    let g2 = document.querySelector('.g2');
    let g3 = document.querySelector('.g3');
    let garageVal;
    if(g1.checked = true){
       garageVal = 15000;
    }else if(g2.checked = true){
       garageVal = 30000;
    } else if(g3.checked = true){
       garageVal = 45000;
    }
    console.log(garageVal);

console will show 15000 by default, despite my efforts, I have not been able to update garageVal.




Aucun commentaire:

Enregistrer un commentaire