<input type="checkbox" class="christmasCheckBox" name="additionalDonationCheckbox" value="yes" id="additionalDonationCheckbox"
<?php echo (isset($_POST['additionalDonationCheckbox'])&&($_POST['additionalDonationCheckbox']!='')) ? 'checked="checked"' : ''; ?> />
$('#additionalDonationCheckbox').click(
function()
{
($(this).attr('checked')) ? alert('checked') : alert('unchecked');
}
);
I have a form, and before I submit it, if i click the checkbox it alerts 'checked' if checked and 'unchecked' if unchecked.
If i submit the form with the checkbox unchecked, (and something else in the form fails my php validation), and then click the checkbox, the above still works correctly.
However, if i submit the form with the checkbox CHECKED, (and something else in the form fails my php validation) and then click the checkbox, whether it is unchecked or checked it just alerts 'checked'.
I am guessing this is because i have set the php code in the input to echo 'checked="checked"', but i cant figure a way around this?