1 Reply Latest reply on Mar 9, 2013 12:57 AM by BKBK

    Having trouble with form field math binding

    siriiven Level 1

      I have a page that outputs a bunch of rows with form fields from a query. I am trying to bind a totals field to some simple math between a couple of the form fields and cannot get it working for some reason. What I am trying to do is:

       

      bind = {((field1_#id# -field2_#id#) + #field3_#id#)}

       

      What would be the best way to go about this?

        • 1. Re: Having trouble with form field math binding
          BKBK Adobe Community Professional & MVP

          <script type="text/javascript">

          function getResult(num1, num2, num3) {

              //converts a blank, space, null, NaN, etc. to 0

              var num1 = num1 || 0;

              var num2 = num2 || 0;

              var num3 = num3 || 0;

              // For decimal numbers, use parseFloat instead

              return parseInt(num1)-parseInt(num2)+parseInt(num3);

          }

          </script>

           

          <!--- My example, just to simulate your context. --->

          <cfset id="x">

           

          <cfform number="mycfform">

              First Number: <cfinput type="text" name="firstnumber_#id#" required="yes"><br>

              Second Number: <cfinput type="text" name="secondnumber_#id#" required="yes"><br>

              Third Number: <cfinput type="text" name="thirdnumber_#id#" required="yes"><br>

              <!--- I have added the 'keyup' event to the last parameter to ensure the result appears immediately, on-key-up.--->

              Calculation Result: <cfinput name="result" type="text" bind="javascript:getResult({firstnumber_#id#},{secondnumber_#id#},{thirdnumber_#id#@keyup })" bindonload="true">

          </cfform>