how to loop to get value of all checked checkboxes?
Copy link to clipboard
Copied
I am a non-techic trying to fix something for work. Your help is really appreciated.
I have a form with checkboxes (4 check boxes). Everything sumbits fine. SQL db is updated perfectly and data is displayed on webpage w/o any problem. However when I go to edit an entry, on the edit form, (if more then one checkbox were selected oringally), non of the checkboxes are checked. If only one checkbox was selected orinally, that checkbox is selected. What am I missing? I know I am suppose to use loop to get all checked checkbox values, but I have no idea how.
Here is my code so far.
<input type="checkbox" name="colors" value="red" <cfif #getResultSet.colors# EQ "red">checked</cfif>>red
<input type="checkbox" name="colors" value="blue" OR<cfif #getResultSet.colors# EQ "blue">checked</cfif>>blue
<input type="checkbox" name="colors" value="green" OR<cfif #getResultSet.colors# EQ "green"></cfif>>green
<input type="checkbox" name="colors" value="yellow" OR<cfif #getResultSet.colors# EQ "yellow">checked</cfif>>yellow
Copy link to clipboard
Copied
JayYaj wrote:
However when I go to edit an entry, on the edit form, (if more then one checkbox were selected oringally), non of the checkboxes are checked. If only one checkbox was selected orinally, that checkbox is selected.
You've given all the checkboxes the same name. Give them each a unique name and you will be able to access them individually. Current standards also require a unique ID, which can (but does not have to) be the same as the name.
The "OR" characters in your code are not doing anything. You can safely delete them.

