Change Cell Colour Based on Checkbox
Posted: Fri Jul 13, 2012 8:10 am
I have a table set up which contains a set of checkboxes, and am looking for a way to change the background colour of the cell, based on whether the checkbox is checked or not.
I have got as far as:
however, it currently doesn't work. Can someone point out where I am going wrong please.
I have got as far as:
Code: Select all
<!--THE TABLE -->
<form name="DBReturn" action="#" method="post">
<table id="DBSelectIgnTable" class="DBSelectTable">
<tr>
<td class="CellWhite "><INPUT TYPE="checkbox" NAME="ignore[]" VALUE="1"></td>
<td class="CellWhite "><INPUT TYPE="checkbox" NAME="ignore[]" VALUE="2"></td>
<td class="CellWhite "><INPUT TYPE="checkbox" NAME="ignore[]" VALUE="3"></td>
<td class="CellWhite "><INPUT TYPE="checkbox" NAME="ignore[]" VALUE="4"></td>
</tr>
</table>
<p class="submitRed">
<input type="submit" Name="submit" value="Ignore These Databases">
</p>
</form>
Code: Select all
<!--THE JAVASCRIPT-->
<script type="text/javascript">
$(document).ready(function()
{
$("#DBSelectIgnTable td :checkbox").click(function()
{
if (this.checked)
{
$(this).addClass('CellRed');
}
else
{
$(this).addClass('CellWhite');
}
}
)
}
);
</script>