I have a dynamic table in my web application that is populated with data from a database. Each row in the table represents multiple time slots for a specific date. I am working on a feature where the background color of a time block can be changed if a checkbox next to it is checked. While I successfully implemented the functionality of the checkbox, I faced challenges when trying to change the background color dynamically based on its status. Here is an excerpt of my code:
<cfoutput query="qryTest" group="DateMeeting">
<tbody>
<tr>
<td>#DateMeeting#</td>
</tr>
<cfoutput>
<tr class="blockRow">
<td>#StartTime#</td>
<td>#EndTime#</td>
<td><input type="checkbox" name="block" id="block"></td>
</tr>
</cfoutput>
</tbody>
</cfoutput>
JavaScript:
$('input[type=checkbox]').on('change', function() {
var div = $(this).closest('.blockRow');
$(this).is(":checked") ? div.addClass("highlight") : div.removeClass("highlight");
});
CSS:
.highlight{
background-color: lightblue;
}
This solution now works seamlessly after making adjustments to the structure of the HTML and utilizing jQuery for better control over elements. With the help of the community, I was able to overcome initial issues and create a user-friendly experience for modifying the appearance of time blocks. Thank you all for your input!