problem with setting checkbox

problem with setting checkbox

I have a checkbox that I want to update a database (check it to set a flag). I have successfully used '.post' to send the data, but I can't consistently get the checkbox to reflect the change. I click it and the check appears, but won't disappear when I click it again. The data is still being sent to the server, but the display is not correct.

  1. <script type="text/javascript">
  2. $(function() {
  3.     $('input:checkbox').click(function(e){
  4.         var newVal = (this.value == 'true')?'false':'true';
  5.         e.preventDefault();
  6.         $.post("<cfoutput>#viewstate.getValue('myself')#</cfoutput>admin.ajax.updateuser", {f:this.name,v:newVal}, function(data) { newVal = data; });
  7.         this.value = newVal;
  8.         this.checked = newVal;
  9.     });
  10. });
  11. </script>
  12. <form name="userform">
  13. User is Admin? <input name="isAdmin" id="isAdmin" type="checkbox" value="false" />
  14. </form>
The problem seems to be in how I'm setting the "checked" attribute, but I've tried every way that I can find!