How do I use the form checkbox value?

Ask a Question related to Coldfusion Flash Integration, Design and Development.

  1. #1

    Default How do I use the form checkbox value?

    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>

    Count Zero Guest

  2. Similar Questions and Discussions

    1. CheckBox required on form?
      I have a form, and we need to have a checkbox that the user is required to check. Basically saying they read the disclaimer. Is there a way to...
    2. Flash Form & Checkbox
      I'm having trouble changing this listbox code to checkboxes instead. Can you help? <cfselect name="binderyID" label = "Bindery Type"...
    3. Checkbox Set To OFF Not In Request.Form
      When using checkboxes on a form, if you uncheck them, the unchecked name/value pair in the Request.Form collection doesn't show up. It only shows...
    4. Form CheckBox question
      Hello, I have this in my form.... the checkUnCheck(this); will uncheck values 1,2,3 if None is chosen... Now when I submit this form, the output...
    5. Yes/No checkbox in the form
      I have a field called action in a table, to check if something requires action the user must check the box. The field in the table is defined as a...
  3. #2

    Default Re: How do I use the form checkbox value?

    > 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
    [url]http://livedocs.adobe.com/flex/15/asdocs_en/mx/controls/CheckBox.html[/url] 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

    -==cfSearching==- Guest

  4. #3

    Default Re: How do I use the form checkbox value?

    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";



    Count Zero Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139