Personally I have a problem!
I have a Radio that I get the value of the bank
<div class="radio">
<label>
<input type="radio" name="empresa_tipo" value="J" <?php echo ($empresa->empresa_tipo == "J") ? "checked" : null; ?> class="ace" />
<span class="lbl"> Pessoa Jurídica</span>
</label>
<label>
<input type="radio" name="empresa_tipo" value="F" <?php echo ($empresa->empresa_tipo == "F") ? "checked" : null; ?> class="ace" />
<span class="lbl"> Pessoa Física</span>
</label>
</div>
But this radio, when selected, executes the function in js that enables or disables some fields
follow script
$(document).ready(function() {
$('input:radio[name="empresa_tipo"]').on("change", function() {
if (this.checked && this.value == 'J') {
$("#razao_social, #CNPJ").show();
$("#data_nascimento, #CPF, #estado-civil, #sexo").hide();
} else {
$("#data_nascimento, #CPF, #estado-civil, #sexo ").show();
$("#razao_social, #CNPJ").hide();
}
});
});
However when I get the value from the bank and step to the radio which will receive Checked, it does not disable or enable, it does not execute the function only when I click on the radio that will execute the function. how do I use the
checked
instead of
change
in function?
Look at the fields
<div class="form-group" id="sexo" >
<label class=" col-sm-3 control-label bolder blue">Sexo</label>
<div class="col-sm-9">
<div class="radio">
<label>
<input type="radio" name="empresa_sexo" id="empresa_sexo" value="M" <?php echo ($empresa->empresa_sexo == "M") ? "checked" : null; ?> class="ace" />
<span class="lbl">Masculino</span>
</label>
<label>
<input type="radio" name="empresa_sexo" id="empresa_sexo" value="F" <?php echo ($empresa->empresa_sexo == "F") ? "checked" : null; ?> class="ace" />
<span class="lbl">Feminino</span>
</label>
<label>
<input type="radio" name="empresa_sexo" id="empresa_sexo" value="O" <?php echo ($empresa->empresa_sexo == "O") ? "checked" : null; ?> class="ace" />
<span class="lbl">Outros</span>
</label>
</div>
</div>
</div>
<div class="space-4"></div>
<div class="form-group" id="CPF" >
<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> CPF </label>
<div class="col-sm-9">
<input type="text" id="empresa_cpf" name="empresa_cpf" value="<?= $empresa->empresa_cpf ?>" class="col-xs-10 col-sm-5 input-mask-eyescript" />
</div>
</div>
<div class="form-group" id="CNPJ" >
<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> CNPJ </label>
<div class="col-sm-9">
<input type="text" id="empresa_cnpj" name="empresa_cnpj" value="<?= $empresa->empresa_cnpj ?>" class="col-xs-10 col-sm-5 input-mask-eyescript-2" />
</div>
</div>
<div class="space-4"></div>