B
B
BIGO232020-04-25 18:57:05
JavaScript
BIGO23, 2020-04-25 18:57:05

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

1 answer(s)
A
Alexey Yarkov, 2020-04-25
@BIGO23

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 question

Ask a Question

731 491 924 answers to any question