Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Location
    Michigan
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Jquery - my calculations are off by $100

    Hello,
    This is my first try with Jquery and for some reason one of my form totals is always off by $100. It is the gr_total_dollars that is off, all others are calculating properly. Here is the code
    Code:
       <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
      $(".TextBox").hover(function(){
        $(this).toggleClass('TextBoxSelected');
      },function(){
        $(this).toggleClass('TextBoxSelected');
      }).change(function(){
        calculate();
      });
    });
    function getFldValue(fldValue) {
      return isNaN(fldValue) ? 0 : parseFloat(fldValue);
    }
    function calculate() {
      var property_SPrice = getFldValue($('#property_SPrice').val());
      var price = getFldValue($('#price').val());
     
      var REO_sale_percentage    = getFldValue($('#REO_sale_percentage').val());
      var REO_sale_dollars       = getFldValue($('#REO_sale_dollars').val());
      var REO_sale_bonus_dollars = getFldValue($('#REO_sale_bonus_dollars').val());
      var REO_sale_fixed_dollars = getFldValue($('#REO_sale_fixed_dollars').val());
      var REO_sale_total_dollars = getFldValue($('#REO_sale_total_dollars').val());
      
    
      var REO_list_percentage    = getFldValue($('#REO_list_percentage').val());
      var REO_list_dollars       = getFldValue($('#REO_list_dollars').val());
      var REO_list_bonus_dollars = getFldValue($('#REO_list_bonus_dollars').val());
      var REO_list_fixed_dollars = getFldValue($('#REO_list_fixed_dollars').val());
      var REO_list_total_dollars = getFldValue($('#REO_list_total_dollars').val());
      
      var gr_comm_percentage     = getFldValue($('#gr_comm_percentage').val());
      var gr_comm_dollars        = getFldValue($('#gr_comm_dollars').val());
      var gr_bonus_dollars       = getFldValue($('#gr_bonus_dollars').val());
      var gr_fixed_dollars       = getFldValue($('#gr_fixed_dollars').val());
      var gr_total_dollars       = getFldValue($('#gr_total_dollars').val());   
    
      $('#price').val(property_SPrice);
      $('#gr_comm_percentage').val(REO_list_percentage + REO_sale_percentage);
      
      $('#gr_comm_dollars').val(getFldValue(gr_comm_percentage/100*price));
      $('#REO_list_dollars').val(getFldValue(REO_list_percentage/100*price));
      $('#REO_sale_dollars').val(getFldValue(REO_sale_percentage/100*price));
      $('#gr_fixed_dollars').val(getFldValue(REO_sale_fixed_dollars + REO_list_fixed_dollars));
      $('#gr_bonus_dollars').val(getFldValue(REO_sale_bonus_dollars + REO_list_bonus_dollars));
      $('#gr_total_dollars').val(getFldValue(gr_comm_dollars + gr_fixed_dollars + gr_bonus_dollars));
      $('#REO_sale_total_dollars').val(getFldValue(REO_sale_dollars + REO_sale_fixed_dollars + REO_sale_bonus_dollars));
      $('#REO_list_total_dollars').val(getFldValue(REO_list_dollars + REO_list_fixed_dollars + REO_list_bonus_dollars));
    
    
    
    }  
    </script>
    
    
    td><cfoutput><cfif #form.list_type# IS 1 OR #form.list_type# IS 2><b>*</b></cfif></cfoutput><b>Sold Price</b> </td>
                                <td><input type="text" id="price" size="8" class="TextBox" onFocus="this.className='TextBoxSelected';select()" onBlur="this.className='TextBox'" onChange="calculate();" /></td>
                                </tr>    
                                <tr><td colspan="2"><b>Commission Information</b>
                                </td>
                                </tr>          
                            <!---Form headings--->
                            <tr><td>&nbsp;</td>
                            <td colspan="2" align="center"><b>Main Commission</b></td>
                            	<td align="center"><b>Fixed</b></td>
                                <td align="center"><b>Bonus/<br />Other</b></td>
                                <td align="center"><b>Total</b></td>
                             </tr>
                             <tr>
                             <td>&nbsp;</td>
                             <td><b>%</b></td>
                             <td><b>$</b></td>
                             <td><b>$</b></td>
                             <td><b>$</b></td>
                             <td><b>$</b></td>
                             </tr>
                             <!---End form headings--->
    						
                                 <tr><td><b>*</b>Gross Comm</td>
        <td><input type="text" id="gr_comm_percentage" size="1" class="TextBox" value="0"> </td>
        <td><input type="text" id="gr_comm_dollars"    size="8" class="TextBox" value="0"> </td>
        <td><input type="text" id="gr_fixed_dollars"   size="8" class="TextBox" value="0"> </td>
        <td><input type="text" id="gr_bonus_dollars"   size="8" class="TextBox" value="0"> </td>
        <td><input type="text" id="gr_total_dollars"   size="8" class="TextBox"> </td>
      </tr>
    						<tr>
    <cfoutput>
      <cfif #form.list_type# IS 2>
        <td><b>*</b>REO List </td>
        <td><input type="text" id="REO_list_percentage"    size="1" class="TextBox" value="0"> </td>
        <td><input type="text" id="REO_list_dollars"       size="8" class="TextBox" value="0"> </td>
        <td><input type="text" id="REO_list_fixed_dollars" size="8" class="TextBox" value="0"> </td>
        <td><input type="text" id="REO_list_bonus_dollars" size="8" class="TextBox" value="0"> </td>
        <td><input type="text" id="REO_list_total_dollars" size="8" class="TextBox"> </td>
                                
                                
                               <!---List type 1 begins here---> 
                                
                                
    							<cfelseif #form.list_type# IS 1 ><td><b>*</b>Amt Pd to O/B</td>
    							<td><input type="Text" name="OB_percentage" size="1" class="TextBox" onFocus="this.className='TextBoxSelected';select()" onBlur="this.className='TextBox'">% </td>
    							<td>$<input type="text" name="OB_dollars" size="8" class="TextBox" onFocus="this.className='TextBoxSelected';select()" onBlur="this.className='TextBox'" > </td>
    							<cfelse><td>Amt Pd to O/B</td>
    							<td><input type="Text" name="OB_percentage" size="1" class="TextBox" onFocus="this.className='TextBoxSelected';select()" onBlur="this.className='TextBox'">% </td>
    							<td>$<input type="text" name="OB_dollars" size="8"  class="TextBox" onFocus="this.className='TextBoxSelected';select()" onBlur="this.className='TextBox'"> </td>
    							</cfif>
    							</cfoutput>
    						</tr>
    						<tr>
    <cfoutput>
      <cfif #form.list_type# IS 2>
        <td><b>*</b>REO Sale  </td><!---Comp. Dollar--->
        <td><input type="text" id="REO_sale_percentage"    size="1" class="TextBox" value="0"> </td>
        <td><input type="text" id="REO_sale_dollars"       size="8" class="TextBox" value="0"> </td>
        <td><input type="text" id="REO_sale_fixed_dollars" size="8" class="TextBox" value="0"> </td>
        <td><input type="text" id="REO_sale_bonus_dollars" size="8" class="TextBox" value="0"> </td>
        <td><input type="text" id="REO_sale_total_dollars" size="8" class="TextBox"> </td>
                       
                           
    							<cfelse><td><b>*</b>REO Gross</td>
    							<td><input type="Text" name="comp_percentage" size="1" class="TextBox" onFocus="this.className='TextBoxSelected';select()" onBlur="this.className='TextBox'">% </td>
    							<td>$<input type="text" name="comp_dollars" size="8"  class="TextBox" onFocus="this.className='TextBoxSelected';select()" onBlur="this.className='TextBox'"> </td>
    Can anyone tell me what I need to change? Thanks in advance for your assistance.

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,395
    Thanks
    12
    Thanked 569 Times in 562 Posts
    Hmm without digging too deep into your code, the calculation logic seems to be a bit off

    FIRST you are reading field values into variables like gr_comm_dollars, gr_fixed_dollars, gr_bonus_dollars ... THEN you are changing the respective field values (without updating the variables) and FINALLY you are calculating gr_total_dollars from the variables (and not from the changed field values). I don't see the logic in here ...


  •  

    Posting Permissions

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