0
Colleagues.
I have a field that I need to enable and disable by clicking on a checked. See:
When I click checked, I can disable, but when I uncheck, the field is still disabled. I am doing so:
JAVASCRIPT
<script type="text/javascript">
function desabilitar(valor){
if(valor == 'sim'){
document.getElementById('tel').disabled = true;
}else{
document.getElementById('tel').disabled = false;
}
}
</script>
HTML
<div class="form-group">
<label for="NomeEscola" style="font-weight: normal">Telefone Residencial:
<input type="checkbox" onclick="desabilitar('sim')"> O mesmo do aluno</label>
<div class="input-group">
<div class="input-group-addon" style="background-color: #FAFAFA">
<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>
</div>
<input type="text" class="form-control" name="TelefoneResidencial" id="tel" data-inputmask="'alias': '(99)9999-9999'" maxlength="150">
</div>
The problem is that at the checkbox click you always pass as "yes". onclick="disable('yes')". Whether he’s marked or not, he’ll always be yes and disable. Check if the field is disabled, if yes, you uncheck, otherwise check.
– Bruno Rigolon