I need to: If the Code field is empty, the Internal Code field can be enabled / empty as well, and if the code field is filled in the internal code field must be disabled (since the internal code is automatically filled in ).
But my code is doing the opposite, it only enables the internal code field after the code is filled. And another, I need to handle the error of case the user enter a value in the field Code and remove the value the field Internal code field is again disabled immediately, have that possibility?
<script type="text/javascript">
var codigo = document.getElementById("codigo");
var codigo_interno = document.getElementById("codigo_interno");
codigo.addEventListener('keyup', function() {
codigo_interno.disabled = codigo.value.trim().length > 0;
});
//agora uma função para keyup muito semelhante para o codigo_interno
codigo_interno.addEventListener('keyup', function() {
codigo.disabled = codigo_interno.value.trim().length > 0;
});
</script>
<label>Código</label>
<input type="text" id="codigo">
<label>Código Interno</label>
<input type="text" id="codigo_interno">