Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML/PHP if-else Statement

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: enter image description here

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:

enter image description here

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

like image 474
Christoph C. Avatar asked Sep 28 '22 03:09

Christoph C.


1 Answers

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");
}
        });
like image 63
Manish Shukla Avatar answered Oct 02 '22 15:10

Manish Shukla