Sharing a name among checkboxesHere's a tip you might have missed. Did you know if you reuse a name for more than one checkbox control in your form, your result on the processing side is a comma-delimited list? This is particularly useful for numeric IDs. Check out this reporting app: <cfquery name="qStatuses" datasource="#dsn#"> SELECT ID, Name FROM Status </cfquery> <cfparam name="Form.StatusIDs" default="#valueList(qStatuses.ID)#"> <cfquery name="qEmployees" datasource="#dsn#"> SELECT * FROM Employee WHERE Status IN (#Form.STatusIDs#) </cfquery> <form method="post"> Include: <cfloop query="qStatuses"> <cfset vChecked = ""> <cfif listFind(Form.StatusIDs, qStatuses.ID )> <cfset vChecked = " checked"> </cfif> <input type="checkbox" name="StatusIDs" value="#qSTatuses.ID#" #checked#> #qStatuses.Name# </cfloop> </form> Results <cfloop query="qEmployees"> ...etc. </cfloop> Because all the checkboxes have the same name ("StatusIDs"), then the value that comes through on the processing side as a comma-delimited list of the IDs of the checkboxes that the user checked, which fits quite nicely in our IN() statement in the query. And before you cry out about the user not checking any of them, remember that an unchecked checkbox does not even get submitted as a value, so in that case, the |
There are no comments for this entry.
[Add Comment]