-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>
1
  • You likely mean to do if (document.getElementById("isPless").checked) ... Commented Jan 24, 2022 at 14:36

1 Answer 1

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>

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.