How to: Select all checkboxes in ColdFusion Flash Forms

Posted August 10, 2005 4:32 pm
Filed under: Articles by Paul, ColdFusion Flash Forms, Flash, Tutorials

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)

Source Code

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

Source Code

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.

  • http://www.pdesigner.net Freelancer

    I’m looking checkbox control for flash page, how to do that?

  • OneFineNight

    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

  • Krishna Chaitanya

    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.

  • arvind

    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

  • Abhishek

    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

  • grietje

    just make a mirror page with same query and property of the checkboxes “checked”

  • Pingback: digital primates IT Consulting Group - Blogs - Mike Nimer's Blog: Paul Robertsons on Flash Forms

Articles by Type

Articles by Topic

Random Reading

Currently...

Adobe MAX 2011 Speaker H. Paul Robertson: Adobe Community Professional

Subscribe