jeudi 18 mai 2017

HTML Checkbox with JQuery (uncheck others and attr)

Im working at register page where u have the option to choose between Personal or Business account. I don't know how to solve this problem. I've wrote some JQuery and kind a work but it dosnt. The attributes changes Works, but only happens one time. I can select "Personal" then "Business" and after that radiobuttons dont work anymore.

<div id="tipoUsuario" class="row">
<div class="col-sm-6 m-b-10">
    <p class="text-muted font-13"> Seleccioná el tipo de cuenta: </p>
    <div class="form-check">
        <label class="custom-control custom-radio">
            <input id="esUsuario" name="esUsuario" value=False type="radio" class="esUsuario custom-control-input">
            <span class="custom-control-indicator"></span>
            <span class="custom-control-description">Personal</span>
        </label>
    </div>
    <div class="form-check">
        <label class="custom-control custom-radio">
            <input id="esEmpresa" name="esEmpresa" value=True type="radio" class="esEmpresa custom-control-input">
            <span class="custom-control-indicator"></span>
            <span class="custom-control-description">Empresa</span>
        </label>
    </div>
</div>

$( document ).ready(function() {
if ($("#tipoUsuario").on("click", function(){
    if ($($(".esEmpresa")).is(":checked")){
        $(".esUsuario").attr("checked", false);
        $("#divUsuario").hide();
        $("#apellidos").attr("required", false);
        $("#nombres").attr("required", false);
        $("#divEmpresa").show();
        $("#nombreEmpresa").attr("required", true);
        $("#cuitEmpresa").attr("required", true);
    } else if ($($(".esUsuario")).is(":checked")) {
        $(".esEmpresa").attr("checked", false)
        $(".esUsuario").attr("checked", true);
        $("#divUsuario").show();
        $("#nombreEmpresa").attr("required", false);
        $("#cuitEmpresa").attr("required", false);
        $("#divEmpresa").hide();
        $("#apellidos").attr("required", true);
        $("#nombres").attr("required", true);
    };
}));
});

Thanks in advance..




Aucun commentaire:

Enregistrer un commentaire