Summarize values when checkbox is checked

Ask a Question related to Macromedia ColdFusion, Design and Development.

  1. #1

    Default Summarize values when checkbox is checked

    Hello all,

    The output of some query shows for example 10 records with invoice prices.
    Before each record is an unchecked checkbox. What I like to do is to check some
    checkboxes to control the total price of the checked invoices. How can I manage
    that?

    Greetings,
    Rudy

    alpenman Guest

  2. Similar Questions and Discussions

    1. Get Checkbox "Checked" value on form submit
      How do I get whether a checkbox is ticked in a form on a form's submission (true or false)? How do I use the Request object in ASP?
    2. DataGrid with CheckBox - How to read checked rows
      I have added a checkbox to a dataset that I bind to a datagrid: DataColumn colBoolean = new DataColumn ("chkBox"); colBoolean.DataType =...
    3. Saving checkbox states (checked or unchecked)?
      Hello. I'm creating a basic form with checkboxes for "yes/no". Is there a way for the state of the checkboxes to be saved by the user (using regular...
    4. Find what checkbox is checked in javascript
      I have to sets of checkboxes. The second is to delete the row. So when I click that checkbox I want to add it to an array. I also need to take it...
    5. Capturing checked event for Template based checkbox.
      Getting to grips with the datagrid better than I thought, however I've hit another problem which hopefully someone will be able to help (again.) ...
  3. #2

    Default Re: Summarize values when checkbox is checked

    What do you mean "control the total price of the checked invoices"?

    Do you want to display the sum of the checked invoices? Javascript can
    easily do that.
    Or is it something else?

    Regards,
    -- MikeR


    MikerRoo Guest

  4. #3

    Default Re: Summarize values when checkbox is checked

    Hello Mike,

    Yes... I want to display the sum of the checked invoices...

    Greetings,
    Rudy
    alpenman Guest

  5. #4

    Default Re: Summarize values when checkbox is checked

    > Hello Mike,
    >
    > Yes... I want to display the sum of the checked invoices...
    Make those checkboxes submit the form to the server and calculate the sum on
    the server.

    <input type="checkbox" name="product_id#id#" onclick="this.form.submit();">

    --
    <mack />


    Neculai Macarie Guest

  6. #5

    Default Re: Summarize values when checkbox is checked

    Ok, the attached code shows you one way to do it -- without having to talk to
    the server at all.

    Just be sure to validate and recalculate, on the server, when the user finally
    submits the form. This guards against acts of browsers, hackers, and nature.

    Regards,
    -- MikeR


    <style type="text/css">
    #ItemTotalDisplay /*--- Double pound signs needed for CF. Use single
    pound otherwise. ---*/
    {
    background-color: #CCFFCC;
    border: 1px solid black;
    padding: 6px;
    font-size: larger;
    }
    </style>

    <form name="frmListItems">
    <p id="ItemTotalDisplay">
    <!--- This next span will be overwritten by javascript. --->
    Total: $<span id="domItemSumDisplay"> 0 </span>
    </p>

    <label for="CB_1">
    <input name="cbItemList" type="checkbox" id="CB_1" value="10.99"
    onclick="cjsSumChkBoxPrices ('frmListItems', 'cbItemList',
    'domItemSumDisplay');">
    Item 1 for $10.99
    </label>

    <label for="CB_2">
    <input name="cbItemList" type="checkbox" id="CB_2" value="3.02"
    onclick="cjsSumChkBoxPrices ('frmListItems', 'cbItemList',
    'domItemSumDisplay');">
    Item 2 for $3.02
    </label>
    </form>


    <script type="text/javascript">
    function cjsSumChkBoxPrices (sFormName, sCB_GrpName, sOutputElementID)
    {
    var zCB_Array = eval ("document.forms." + sFormName + "." +
    sCB_GrpName);
    var fSum = 0;
    var zCntDisplay = document.getElementById (sOutputElementID);
    var iNumCBoxes = zCB_Array.length;

    for (iCBIdx=0; iCBIdx < iNumCBoxes; iCBIdx++)
    {
    if (zCB_Array[iCBIdx].checked)
    {
    fSum += (zCB_Array[iCBIdx].value - 0); //-- minus zero
    forces number convert.
    }
    }

    //--- Write the sum to the display span. ---
    zCntDisplay.innerHTML = fSum;
    }
    </script>

    MikerRoo Guest

  7. #6

    Default Re: Summarize values when checkbox is checked

    Hello Mike,

    I have implemented your code in the page and it works fine for me! I have an
    extra checkbox for each record because the value in the original checkbox is
    the ID of the record and not the invoice value (the money).

    Thanks in advance,
    greetings Rudy

    alpenman Guest

  8. #7

    Default Re: Summarize values when checkbox is checked

    Thanks for the feedback.

    But, having two checkboxes may be annoying to your users.

    Post another question if you want help with that. (One solution would be for
    your code to write a javascript lookup table that cjsSumChkBoxPrices() would
    then use to translate DB ID to price.)

    Regards,
    -- MikeR



    MikerRoo 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