Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I use the form checkbox value?

11 views
Skip to first unread message

Count Zero

unread,
Nov 4, 2008, 11:23:55 AM11/4/08
to
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.


<cfsavecontent variable="calcCost">
var accumulator = 0;

var ch1 = chkBox_test1;
var ch2 = chkBox_test2;
var ch3 = chkBox_test3;
var ch4 = chkBox_test4;
var ch5 = chkBox_test5;

AND NOW HERE IS THE PROBLEM - HOW DO I TEST IF A CHECKBOX HAS BEEN SELECTED?
HOW DO I MAKE USE OF THE CHECKBOX VALUE TO ADD TO MY ACCUMULATOR?

/*****************************************************************
JavaScript lets me do something on the order of
if( form.chkBox_test1.checked == true )
{
if( form.chkBox_test1.value <> 0 )
accumulator += form.chkBox_test1.value;
}
else
{
do something else..........
}
*****************************************************************/

// How do I do the same thing in ColdFusion ActionScript?


Cost.text = accumulator;

// ALSO: is there a way to display the various values/objects? For instance,
JS has alert();
</cfsavecontent>


<cfform name="myForm" action="my url whatever" format="flash" method="post"
width="510" height="1200" skin="halogreen" preloader="true">
<cfinput name="Cost" label="Your cost will be: " type="text" size="10"
value="00.00">

<cfformgroup type="tabnavigator">
<cfformgroup type="page" label="1. Simple Test - Cost Selector">
<cfformitem type="text">Please select the options you would
like.</cfformitem>

<cfformgroup type="hdividedbox">
<cfformgroup type="vbox">
<cfinput name="chkBox_test1" type="checkbox" label="Option 1 $1.00"
value="1" onClick="#calcCost#">
<cfinput name="chkBox_test2" type="checkbox" label="Option 2 $2.00"
value="2" onClick="#calcCost#">
<cfinput name="chkBox_test3" type="checkbox" label="Option 3 $3.00"
value="3" onClick="#calcCost#">
<cfinput name="chkBox_test4" type="checkbox" label="Option 4 $4.00"
value="4" onClick="#calcCost#">
<cfinput name="chkBox_test5" type="checkbox" label="Option 5 $5.00"
value="5" onClick="#calcCost#">
</cfformgroup>
</cfformgroup>
</cfformgroup>
</cfformgroup>
</cfform>

-==cfSearching==-

unread,
Nov 10, 2008, 10:34:31 PM11/10/08
to
> 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
http://livedocs.adobe.com/flex/15/asdocs_en/mx/controls/CheckBox.html 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

Count Zero

unread,
Nov 17, 2008, 3:22:29 PM11/17/08
to
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";

0 new messages