Question:
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:
<script>
$(document).ready(function(){
$("#txtEntrada").blur(function(){
if ($("#txtEntrada").val() !=''){
$('#txtSaida').attr("disabled", true);
}else{
$('#txtSaida').attr("disabled", false);
}
});
});
</script>
Anyone with a better suggestion?
Answer:
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 = e.target;
if(['entrada','saida'].indexOf(self.id) !== -1) {
var el = document.getElementById(self.id === 'entrada' ? 'saida' : 'entrada');
self.removeAttribute('disabled');
el.setAttribute('disabled','');
el.value = "";
}
})
<input type="text" id="entrada" name="entrada">
<input type="text" id="saida" name="saida">