Answer the question
In order to leave comments, you need to log in
If one field is filled then the other is disabled?
Good day. How to implement if one field is filled then the other is disabled and vice versa if field 2 is filled then field 1 is not available
Answer the question
In order to leave comments, you need to log in
https://jsfiddle.net/0t1fkpjv/
<input type="text" id="i1">
<input type="text" id="i2">
const i1 = document.querySelector('#i1');
const i2 = document.querySelector('#i2');
i1.addEventListener('input', function (e) {
if (e.target.value) {
i2.setAttribute('disabled', true);
} else {
i2.removeAttribute('disabled');
}
});
i2.addEventListener('input', function (e) {
if (e.target.value) {
i1.setAttribute('disabled', true);
} else {
i1.removeAttribute('disabled');
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question