mardi 2 février 2016

How ot uncheck Bootstrap check box

I am trying to check and uncheck the bootstrap checkbox. I am using a var test. which value I am getting from DB. If the value is zero(0) I want to uncheck the checkbox, and if the value is one(1) I want to check the checkbox. it looks pretty simple.

JQuery

if(test == 0)
        {                                
          $('#myCheck').prop('checked',false);
      alert("I am false");
        }
        else
        {
          $('#myCheck').prop('checked',true);
          alert("I am True");
        }

HTML

<div class="row">
     <div class="col-sm-2"><label class="control-label" for="pwd">My checkbox: </label></div>
                <div class="col-sm-1">
         <span class="button-checkbox">
                                <input type="checkbox" class="hidden" checked id="myCheck" />
         <button type="button" class="btn-chk" data-color="success" ></button>
                                </span>
                </div>                                                                                              
</div>

When the test is zero(0), it comes into the if block and I get the alert message I am false and when it's true I come into else block I get the message I am true but, Checkbox is always checked. Where I am making mistake?. I wpold appricate any help .




Aucun commentaire:

Enregistrer un commentaire