0
Welcome Guest! Login
0 items Join Now

Javascript calculation include for module

    • CaveDog's Avatar
    • CaveDog
    • Hero Rocketeer
    • Posts: 317
    • Thanks: 2

    Javascript calculation include for module

    Posted 13 years 3 months ago
    • I am rebuilding a web site in Joomla 1.7, Camber template. I am trying without success to create a module that will use an 'include' that is currently being used on the current site. The include is a javascript calculator that calculates a percentage of a number placed in an input field. The content, text, number field and calculate button are in the module but the calculation script doesn't work.

      You can look at the old site and see the working calculate.inc here: https://www.unionhomeservices.com/index.php , under "Calculate Your Rebate Savings Now!"

      You can look at the 1.7/Camber module here: http://unionhomeservices.com/newsite/ , under "Cash Back Calculator".

      I am including the entire calculate.inc include below. I have uploaded this to the includes folder. Any help would be greatly appreciated. I obviously am brain dead about this. It's probably some simple thing but I can't figure it out.

      Thanks.

      "calculate.inc" code
      <h1 class="section"><b>Calculate Your Rebate Savings Now!</b></h1>
      <div class="content">
      <p>Use our calculator to determine just how much money you may be able
      to save by using the Union Home Services™ Real Estate Benefit Program.
      Calculator is based on a real estate agent commission of 3%.
      Commissions may vary.</p>
      <p>Enter the price of the home you want to buy or sell and click 'Calculate'
      to see the approximate rebate.</p>

      <div id="calculate">
      <h3>Home Price:</h3>
      <div id="form">
      <input type="text" id="inputValue" name="inputValue" value="" size="6" style="width: 6em"/>
      <script type="text/javascript">
      function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2) {var x = Math.round(num * Math.pow(10,dec));if (x >= 0) n1=n2='';var y = (''+Math.abs(x)).split('');var z = y.length - dec; if (z<0) z--; for(var i = z; i < 0; i++) y.unshift('0');y.splice(z, 0, pnt); while (z > 3) {z-=3; y.splice(z,0,thou);}var r = curr1+n1+y.join('')+n2+curr2;return r;}
      function Calculate(){
      // good, but does not work in Firefox: var inputValue2 = parseInt(inputValue.value);
      // better, as this works in Safari and Firefox:
      var inputValue2 = parseInt(document.getElementById('inputValue').value);
      var rebate = (inputValue2 * .03 * .20);
      var commission = (inputValue2 * .03);
      rebate=formatNumber(rebate,2,',','.','$ ','','',' CR');
      commission=formatNumber(commission,2,',','.','$ ','','',' CR');
      //document.getElementById("commission").innerHTML = "<p>Total Commission: " + commission + "</p>";
      document.getElementById("rebate").innerHTML = "<p>Your rebate of 20%: " + rebate + "</p>";
      }
      </script><br /><br />
      </div>
      <p class="small">Note: Numbers only - no dollar signs or commas.</p>
      <!--div align="center"><span id="commission"></span></div><br-->
      <!--table><tr><td align="center"><div align="center"><span id="rebate">&nbsp;</span></div></td></tr></table-->
      <div align="center"><span id="rebate">&nbsp;</span></div>

      <h3>Your Union Home Services&#8482; 20% Rebate</h3>
      <input type="image" value="Calculate" onclick="Calculate()" src="images/calc.jpg"/>
      </div><br />

      <p class="small"><strong>Disclaimer:</strong> This calculator makes a few assumptions, and the final amount
      may vary depending on your specific situation. The real estate agent
      commission percentage listed in the calculator is an estimate based
      on a 3% commission structure. Commissions may vary and the actual
      percentage you receive will be based on the listing agent's
      agreement.</p>

      </div>

Time to create page: 0.066 seconds