0

How can I change the label color for this checkbox if the checkbox is disabled change the text color to red and if it's not change to green.

Here is my code:

<?php
if ($timelists[]='09:00:00'){
?>
<div class="checkbox checkbox-success checkbox-info text-danger">
<input id="checkbox-15" type="checkbox" name="timelist[]"value="09:00:00" <?php echo (in_array("09:00:00", $timelists)?"disabled='disabled'":"") ?>>
<label for="checkbox-15">
09:00 AM - 10:00 AM (ALREADY SCHEDULED)
</label>
</div>
<?php
}
else{
?>
<div class="checkbox checkbox-success checkbox-info text-success">
<input id="checkbox-15" type="checkbox" name="timelist[]"value="09:00:00" <?php echo (in_array("09:00:00", $timelists)?"disabled='disabled'":"") ?>>
<label for="checkbox-15">
09:00 AM - 10:00 AM (AVAILABLE)
</label>
</div>
<?php
}
?>

In This case the checkbox is disabled and label color is red 'text-danger' I got the same ouput when is not disabled and supposed to be the label color is green 'text-success'

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Elekpato
  • 11
  • 3

1 Answers1

0

As the label is immediately after the checkbox you can harness the simple rules available in standard CSS. In this instance the adjacent sibling selector can be used by defining the style with +

So:

:disabled + label{ /* styles for label... */ }

as in

label { color: green; } /* how the labels will look normally */

input[type="checkbox"]:disabled+label {
  color: red!important
} /* labels for checkboxes that are disabled */

input[type="checkbox"]:disabled + label:after{ content:"( ALREADY SCHEDULED )" }
<div class="checkbox checkbox-success checkbox-info text-danger">
 <input id="checkbox-15" type="checkbox" name="timelist[]" value="09:00:00" disabled />
 <label for="checkbox-15">09:00 AM - 10:00 AM</label>
</div>

<div class="checkbox checkbox-success checkbox-info text-danger">
 <input id="checkbox-16" type="checkbox" name="timelist[]" value="10:00:00" />
 <label for="checkbox-16">10:00 AM - 11:00 AM</label>
</div>
label{color:green;}
label:after{content:"( AVAILABLE )"}
input[type="checkbox"]:disabled + label{color:red!important}
input[type="checkbox"]:disabled + label:after{content:"( ALREADY SCHEDULED )"}
Professor Abronsius
  • 33,063
  • 5
  • 32
  • 46