Skip to main content
Participant
November 4, 2008
Question

How do I use the form checkbox value?

  • November 4, 2008
  • 2 replies
  • 2258 views
I'm creating a form that has multiple checkboxes. I want to use ActionScript to update a text box/area with the values each checkbox as the checkbox is selected. Any ideas on how I might do that?

SAMPLE CODE ATTACHED.
This topic has been closed for replies.

2 replies

Participant
November 17, 2008
I figured out how to do it using both the last poster's comments, and some others that I found.

A form is created using cfform format=flash.
A cfinput text box is created and flagged as not visible.

The "invisible" input value is set after a cfoutput query="xxxx"
is completed.

Since I'm using the query to do double duty, I have a group set.
My "second" group is the one on which I wanted the check boxes to
be created dynamically.

I set a counter, and kept track of when a check box was created.
The value of the counter was eventually set as the value of my
first "invisible" text box.

Here's the code:
<cfformgroup type="horizontal" height="1" visible="no">
<cfif #BoxCount# GT 0>
<cfoutput><cfinput name="BoxQty" type="text" value="#BoxCount#" visible="no" size="3"></cfoutput>
</cfif>
</cfformgroup>


Each check box was given a unique name, text + counter.
ex. camp#BoxCount#
A corresponding "invisible" text box was created:
ex. cost#BoxCount#

This way I can test if the check box "value" is true/false, and
set a cost accumulator to the proper cost.

My cfsavecontent code looks like this:
// COST TOTAL
var a = Number(BoxQty.text);

var i = 0;
var j = 0;
var u = 0;
var x = 0;

var s = "";

for( i=1; i<=a; i++ )
{
r = "camp"+i;
if( eval(r).value ) // just like the JS eval()
{
// box was checked, i.e. is "true"
s = "cost"+i;
j = Number(eval(s).text);

if( j > 0 ) x = x + j; // add to the total accumulator
}
}

//campCost is the cfinput text box used to display the total cost.
campCost.text = 0;

if( x != 0 )
campCost.text = "$" + x + ".00";

Inspiring
November 11, 2008
> HOW DO I TEST IF A CHECKBOX HAS BEEN SELECTED?
> // ALSO: is there a way to display the various values/objects? For instance, JS has alert();

Yes, from an html perspective checkboxes confusingly use the selected property, rather than checked. However, actionscript does have alerts. The simplest form is very similar to a javascript alert.

<!--- displays a message only if the first checkbox was checked --->
<cfsavecontent variable="calcCostAmount">
if (chkBox_test1.selected) {
alert("chkBox_test1 is checked");
}
</cfsavecontent>

> HOW DO I MAKE USE OF THE CHECKBOX VALUE TO ADD TO MY ACCUMULATOR?

That is bit trickier. I am not an flash guru. But as I understand it checkboxes do not use values like their html counterparts. The checkbox value is either "true" if checked or "false" if unchecked. There may be better methods, but you might try storing the values "1,2,3,...5" in hidden fields. Then use a loop to total them. Assuming onClick is the correct event to use here ..

HTH