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