javascript – Disable input text when clicking on another input text


Good afternoon,

I have the two inputs below:

<input type="text" id="txtEntrada" name="entrada" onkeyup="somenteNumeros(this);" >     
<input type="text" id="txtSaida" name="saida" onkeyup="somenteNumeros(this);">

I would like that when clicking on the Input Input the Output would be disabled and vice versa. I'm doing it as follows:

    if ($("#txtEntrada").val() !=''){
      $('#txtSaida').attr("disabled", true);
      $('#txtSaida').attr("disabled", false);

Anyone with a better suggestion?


As I understand it, you need that when you click on an input the other disables it right? So I made a script using just JavaScript.

document.addEventListener('click', function(e) {
  var self =;
  if(['entrada','saida'].indexOf( !== -1) {
    var el = document.getElementById( === 'entrada' ? 'saida' : 'entrada');
    el.value = "";
<input type="text" id="entrada" name="entrada">     
<input type="text" id="saida" name="saida">
Scroll to Top