How to: Select all checkboxes in ColdFusion Flash Forms
Part 1 of My first foray into ColdFusion Flash Forms.
I actually came up with two different approaches to this problem, because we figured out two different ways to dynamically create form fields in Flash forms. Conceptually they are similar, of course; you have a button which calls some ActionScript code that loops through all the checkboxes and sets their “selected” property to true. Unfortunately the implementation details are pretty different.
Approach 1: Using cfformgroup type="repeater" (Flex creates the checkboxes)
In this approach, the checkbox controls are dynamically created by the SWF file. The Flex code that creates them conveniently creates an array whose elements are the dynamically created checkbox controls, so we just loop through that array and set the “selected” property of each element to true (or false for “deselect”). The array variable you use has the same name as the name you give to the cfinput type="checkbox" in your ColdFusion code. Your ColdFusion code to create the repeating checkboxes looks something like this:
.
.
.
<cfformgroup type="repeater" query="q1">
<cfinput type="Checkbox" name="chk" Label="{q1.currentItem.firstname}">
</cfformgroup>
.
.
.
Flex automatically creates an array named “chk” which you can refer to in your ActionScript code, whose elements are the Checkbox controls.
Approach 2: Use cfloop to create multiple checkboxes in the form
In this approach, the checkbox controls are created in a cfloop that runs on the server. To create the “select all” functionality we just loop through our query and dynamically create the ActionScript that will be used by the “select all” button like this:
<cfsavecontent variable="selectAllClick">
<cfloop query="q1">
<cfoutput>boxMBAa_#q1.id#.selected = true;</cfoutput>
</cfloop>
</cfsavecontent>
Note: Unfortunately the only ColdFusion servers I have access to belong to my employer, so I can only post source code and not working examples on my personal site. Sorry!
Comparing the two approaches
Approach 1 advantage
The repeating controls are actually generated in ActionScript in the SWF file, not on the server, so when the data changes the SWF file doesn’t need to be recreated by the server. See the article “Creating ‘dynamic’ form fields in ColdFusion Flash Forms - how and why” for more details.
Approach 2 advantage
Each checkbox control is submitted as a separate form field (name/value pair); you can define the names given to the form fields. See the article “Getting meaningful data from dynamically generated fields in ColdFusion Flash Forms” for more details.
Approach 1 disadvantage
The checkbox values are submitted as two lists, one containing true/false values indicating whether a checkbox was checked or not, and the other containing a list of “id” values which correspond to the true/false values. See the article “Getting meaningful data from dynamically generated fields in ColdFusion Flash Forms” for more details.
Approach 2 disadvantage
The repeating controls are generated by the ColdFusion server before creating the MXML and subsequent SWF file. When the data changes (and maybe every time the page is requested) the server must regenerate the MXML and recompile the SWF. See the article “Creating ‘dynamic’ form fields in ColdFusion Flash Forms - how and why” for more details.
Next: Advice for building and debugging ColdFusion Flash Forms, from one beginner to another
You can leave a comment, or trackback from your own site.
7 Comments so far
Add your comment
Comment notes
Please keep comments on topic. Comments that are inappropriate or offensive will be edited or removed.
Paragraphs and line breaks are automatically converted to HTML, and quotation marks are converted to “smart” quotes.
The following XHTML tags can be used: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> . All others will be removed.
November 22nd, 2005 at 4:12 pm
Freelancer is reported to have said:
I’m looking checkbox control for flash page, how to do that?
November 23rd, 2005 at 11:14 am
OneFineNight is reported to have said:
I cann’t get the repeater to work for me. I cut and past your code in a template by itself and it works fine, when I add it to my template and did not work.
I don’t know what I’m doing wrong… can you help
February 10th, 2006 at 6:37 am
Krishna Chaitanya is reported to have said:
I have a small problem in my project.Its as follows:
I am working with ASP and SQL SERVER 2000
I need to loop through the checkboxes and based on that dynamically make insertions into database.
December 27th, 2006 at 4:32 pm
arvind is reported to have said:
sir i wanted to know abot state manegennt , and can i use in datagrid /datalist/repeter in cold fusion such as asp.net then plz send me details on my mail with source code
regards arvind
January 27th, 2007 at 12:45 am
Abhishek is reported to have said:
dear sir,
i will use a repeter and in there i can use a checkbox and i will also use a radiobutton in same itemtemplet if it is possible plz give me the code.
thankyou
November 16th, 2007 at 11:11 am
grietje is reported to have said:
just make a mirror page with same query and property of the checkboxes “checked”
April 2nd, 2008 at 11:20 am
digital primates IT Consulting Group - Blogs - Mike Nimer's Blog: Paul Robertsons on Flash Forms is reported to have said: