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>
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>