vendredi 4 mai 2018

JAVASCRIPT - I need to check all other camps when one is checked and clean when is unchecked

JAVASCRIPT - I have camps that are like sub items of an item. So, in this case I need to check all other camps when the 'master' item is checked and clean when unchecked. But just the default, because i can have the option of just select a sub item, but the above needs to be selected. And I want that this sub camps just appear when the 'master' item is checked.

<div class="col-md-6">
 <h4>Checkbox Buttons</h4>
    <div class="funkyradio">
        <div class="funkyradio-info">
            <input name="area" type="checkbox"  id="paiadm" onchange="myFunction()">
            <label for="paiadm">Administrativo</label>
        </div>  
        <div class="funkyradio-success">
             <input name="pbitadm" type="checkbox" value="Comercial" id="Comercial" >
             <label for="Comercial">Comercial</label>
        </div> 
        <div class="funkyradio-info">
            <input name="pbitadm" type="checkbox" value="Passagem" id="Passagem" >
            <label for="Passagem">Passagem</label>
        </div>  
        <div class="funkyradio-success">
          <input name="pbitadm" type="checkbox" value="Supri" id="Supri">
          <label for="Supri">Suprimentos</label>
        </div> 


window.onloadfunction Inicializa(){
    var x = document.getElementsByName("pbitadm");
    var i;
    for (i = 0; i < x.length; i++) {
        if (x[i].type == "checkbox") {
            x[i].style.display = "none";
        }
    }
}

function myFunction() {
    var x = document.getElementsByName("pbitadm");
    var y = document.getElementById("paiadm");
    var i;
    if (y.checked == true){
        for (i = 0; i < x.length; i++) {
            if (x[i].type == "checkbox") {
                x[i].checked = true;
                x[i].disabled = false;
            }
        }
    }
    if (y.checked == false){
        for (i = 0; i < x.length; i++) {
            if (x[i].type == "checkbox") {
                x[i].checked = false;
                x[i].disabled = true;
            }
        }
    }
}




Aucun commentaire:

Enregistrer un commentaire