How do I make sure with JavaScript that when I click on the checkbox, the input field gets the number 0?

92 views Asked by At
1

There are 1 answers

4
vjspranav On

I need more than that, but for answering I am assuming your checkbox has id=chkbox

what we can do is add an event listener to the checkbox

let checkbox = document.getElementById("chkbox");
let inp = document.getElementById("number");
checkbox.addEventListener('change', function() {

  if (this.checked) {
      inp.value = 0;
  }
});

This should do the trick