Having trouble with checkboxes that are being pre-checked (when fetching record from mysql).
So I am trying to create a way for users to edit a record in the database. One of the items on the form is a checkbox. I check to see if the record being edited has this feature, if it does I check the box. When I attempt to uncheck it, then use jquery/ajax to submit the form and update, it still sees the box as checked. Using firebug, I noticed that when I uncheck and check the box, it never removes the attribute checked=’checked’. Any ideas??
Here is the checkbox code
<input type="checkbox" id="account_ad_city" value="1" <?PHP if($row['hascityad']==1)echo "checked=\"checked\"";?>>
JQuery/AJAX value setting of checkbox before passing to mysql update page:
if($('#account_ad_city').attr('checked'))
var ad_city = $('#account_ad_city').val();
Use
Try it here – http://jsfiddle.net/FloydPink/mvdzS/
And this answer here on SO itself gives a good explanation on the difference between
.attr()and.prop()