Hi Guys,
Having a problem with checkboxes.
I have fields that need true/false answers, and I'm using checkboxes for that.
If the box is checked, it's true, if it's unchecked, it's false.
The problem I am having is that if the box is already checked (the existing value is true), when I uncheck it, and then submit the form, it's still processing the value as true.
A query is run before populating the form. The query finds the existing values. I'm using CFML, but the logic should be clear. If the value in the database is false, then the box won't be checked (because the if/then statement bases whether or not the box is checked based on that value). So if the database value is false, and the box is unchecked, it doesn't check it as true. But if the value is true, and I uncheck it, it doesn't change the value to false. It's as if having the checkbox unchecked doesn't do anything. I'm wanting it to pass the value as false.
<input type="checkbox" name="my_checkbox" value="1" <cfif myquery.my_checkbox eq "1">checked</cfif>>
<span class="mediumtext">my checkbox</span>
With this code, leaving the checkbox unchecked does not pass the value as false, it simply doesn't change the existing value.
What am I doing wrong here?
Having a problem with checkboxes.
I have fields that need true/false answers, and I'm using checkboxes for that.
If the box is checked, it's true, if it's unchecked, it's false.
The problem I am having is that if the box is already checked (the existing value is true), when I uncheck it, and then submit the form, it's still processing the value as true.
A query is run before populating the form. The query finds the existing values. I'm using CFML, but the logic should be clear. If the value in the database is false, then the box won't be checked (because the if/then statement bases whether or not the box is checked based on that value). So if the database value is false, and the box is unchecked, it doesn't check it as true. But if the value is true, and I uncheck it, it doesn't change the value to false. It's as if having the checkbox unchecked doesn't do anything. I'm wanting it to pass the value as false.
<input type="checkbox" name="my_checkbox" value="1" <cfif myquery.my_checkbox eq "1">checked</cfif>>
<span class="mediumtext">my checkbox</span>
With this code, leaving the checkbox unchecked does not pass the value as false, it simply doesn't change the existing value.
What am I doing wrong here?
