jquery boolean check to see which are selected -
i have 4 checkboxes uses boolean check see have been selected. issue having trying see if 2 of these boxes have been checked. if so, show alert. if .tb1 , .tb3 show alert inpatient. if .tb2 , .tb3, alert "outpatient" , @ default, display "default".
gatestatus(); var inpatient = false; var outpatient = false; var contract = false; function gatestatus(){ if(inpatient == true && contract == true){ alert("in patient gate open"); } else if (outpatient === false && contract == true) { alert("outpatient gate open"); } else{ alert("default"); } $("#result1").on("click", ".tb1", function(){ var inpatient = true; gatestatus(); } $("#result1").on("click", ".tb2", function(){ var outpatient = true; gatestatus(); } $("#result2").on("click", ".tb3", function(){ var contract= false; gatestatus(); } $("#result2").on("click", ".tb4", function(){ var contract= false; gatestatus(); }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div id="result1"> <input type="checkbox" name="1" class="tb2"/> outpatient<br><input type="checkbox"class="tb1" name="1"/> inpatient<br><br></div> </div> <div id="result2"> <input type="checkbox" class="tb4" /> yes<br><input type="checkbox"class="tb3" /> no<br><br></div><br> </div>
us instead...?
function gatestatus() { if($('.tb1').is(':checked') && $('.tb3').is(':checked')) console.log('inpatient'); else if($('.tb2').is(':checked') && $('.tb4').is(':checked')) console.log('outpatient'); } $(".tb1, .tb2, .tb3, .tb4").on("change", function(){ gatestatus(); ));
Comments
Post a Comment