I am creating a website with Bootstrap and I would like to enter an if-else statement but I do not know how to do that. Let me explain:
Here is an image of my current HTML snippet:
Now what I want is, that if I change from "OFF" to "ON" by "An- / Ausschalten" that automatically the "Status aktuell" turns from "OFF" to "ON" and also the other way so it should look like this:
My current HTML code for this part is:
<div class="col-xs-12 col-sm-4 col-md-4 col-lg-4">
<div class="services-wrapper">
<h3>GENERALSTEUERUNG</h3>
Steuern Sie mit nur einem Klick die komplette Lichtanlage Ihres Hauses.<br><br>
<b>Status aktuell:</b> <input id="switch-offColor" type="checkbox" data-off-color="warning" data-size="mini" readonly><br><br>
<b>An- / Ausschalten:</b> <input id="switch-offColor" type="checkbox" data-off-color="warning" data-size="mini">
</div>
</div>
Can someone tell me what if-else code I have to use to make this possible? What should the code look like so that this works?
I would really appreciate your help.
Thanks, Chris
Hi what you need to do is
first you track checkbox change event using
$('#ID').change(function() {
// do any thing
});
Then you have to set checked property of other checkbox
like
$("#id").attr("checked","checked");
your code should like similer to
$('#ID').change(function() {
var checked = $("#id").prop("checked");
if (checked){
$("#id").attr("checked","checked");
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With