-2

I want to create a function to see if a checkbox is checked or not and if so, run updateDocs().

I created the below but const isChecked = document.querySelector('#isPaperless'); does not seem to be correct. How is this done?

isChecked() {
  const isChecked = document.querySelector('#isPless');

  if (isChecked) {
    this.edocsService.updateEdocsStatus();
  }
}
<label htmlFor="isPless">
    <input id="isPless" name="isPless" type="checkbox" /> I want to receive my policy documents 
</label>
runnerpaul
  • 5,942
  • 8
  • 49
  • 118

1 Answers1

0

const input = document.getElementById('isPless');

function isChecked() {

    console.log("status : " + this.checked)

    if (this.checked) {
        
        this.edocsService.updateEdocsStatus();
    }
}

input.addEventListener("click", isChecked); 
<label htmlFor="isPless">
    <input id="isPless" name="isPless" type="checkbox" /> I want to receive my policy documents 
</label>
Co-7
  • 170
  • 11