I am trying to disable all input type in a form when one of them is checked or filled with a value.
When one of the checkbox is checked will disable the other two fields, same for the input text.
Here some code try:
HTML
<form action="">
<input type="text" id="name"/>
<input type="checkbox" id="days" name="days" />
<input type="checkbox" id="months" name="months" />
</form>
JS
function disableInput(e) {
if(e.target.value !== 0) {
document.getElementById("days").disabled = true;
document.getElementById("months").disabled = true;
}else {
document.getElementById("days").disabled = false;
document.getElementById("months").disabled = false;
}
}
const name = document.querySelector('#name');
name.addEventListener('input', disableInput);
How can I manage this in vanilla JS?