title: Simple calculation php
body: <p>hye guy,
  Actually i'm still new in programming.
  just wanna asking what wrong with this code?
  i'm trying to make calculation inside a form.
  Really appreciate if your guys can help.
  Thank you.</p>
  
  <pre><code>&lt;?php
  $script = "
  window.addEvent('domready', function() {
  function calculate() {
  
  var value1 = $('value1').value;
  var value2 = $('value2').value;
  var value3 = $('value3').value;
  var value4 = $('value4').value;
  var value5 = $('value5').value;
  
  
  var total = ( value1 + value2 + value3 + value4 + value5);
  
  
  // Check that the result is a finite number. If so, display the results.
  if (!isNaN(monthly) &amp;&amp;
    (monthly != Number.POSITIVE_INFINITY) &amp;&amp;
    (monthly != Number.NEGATIVE_INFINITY)) {
  
  
    total.value = round(value1 +value2 +value3 +value4 + value5);
  
  } else {
    // Otherwise, the user's input was probably invalid, so don't
    // display anything.
  
    total.value = '';
  
  }
  } 
  
  // rounds number to two decimal places.
  function round(x) {
  return Math.round(x*100)/100;
  }
  $('compute').addEvent('click', calculate );
  $('value1').addEvent('change', calculate );
  $('value2').addEvent('change', calculate );
  $('value3').addEvent('change', calculate );
  $('value4').addEvent('change', calculate );
  $('value5').addEvent('change', calculate );
  
  
   });
  ";
  $doc =&amp; JFactory::getDocument();
  $doc-&gt;addScriptDeclaration($script);
   ?&gt;
  &lt;table&gt;
  &lt;tr&gt;&lt;td colspan="3"&gt;&lt;b&gt;Enter Amount Information:&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;1)&lt;/td&gt;
    &lt;td&gt;Amount of the 1 :&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="value1" id="value1" size="12" &gt;&lt;/td&gt;
   &lt;/tr&gt;
  
  &lt;tr&gt;
    &lt;td&gt;2)&lt;/td&gt;
    &lt;td&gt;Amount of the 2 :&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="value2" id="value2" size="12" &gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
    &lt;td&gt;3)&lt;/td&gt;
    &lt;td&gt;Amount of the 3 :&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="value3" id="value3" size="12" &gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
    &lt;td&gt;4)&lt;/td&gt;
    &lt;td&gt;Amount of the 4 :&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="value4" id="value4" size="12" &gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;5)&lt;/td&gt;
    &lt;td&gt;Amount of the 5 :&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="value5" id="value5" size="12" &gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;&lt;td colspan="3"&gt;
    &lt;input type="button" value="Compute" id='compute' " &gt;
  &lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td colspan="3"&gt;
    &lt;b&gt;Payment Information:&lt;/b&gt;
  &lt;/td&gt;&lt;/tr&gt;
  
  
  &lt;tr&gt;
    &lt;td&gt;5)&lt;/td&gt;
    &lt;td&gt;Your total will be:&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="total" id="total" size="12" readonly='readonly'&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;/table&gt;
  ?&gt;
  </code></pre>
  
  <p>Regards,
  ADik mat</p>