Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Google is your friend... As is StackOverflow!!</p> <p>You need to use JavaScript here, perhaps as well as PHP...</p> <p><strong>Restrict to Numbers with decimal place:</strong></p> <p><a href="https://stackoverflow.com/questions/2808184/restricting-input-to-textbox-allowing-only-numbers-and-decimal-point">Restricting input to textbox: allowing only numbers and decimal point</a></p> <pre><code>&lt;HTML&gt; &lt;HEAD&gt; &lt;SCRIPT language=Javascript&gt; &lt;!-- function isNumberKey(evt) { var charCode = (evt.which) ? evt.which : event.keyCode; if (charCode != 46 &amp;&amp; charCode &gt; 31 &amp;&amp; (charCode &lt; 48 || charCode &gt; 57)) return false; return true; } //--&gt; &lt;/SCRIPT&gt; &lt;/HEAD&gt; &lt;BODY&gt; &lt;INPUT id="txtChar" onkeypress="return isNumberKey(event)" type="text" name="txtChar"&gt; &lt;/BODY&gt; &lt;/HTML&gt; </code></pre> <p><strong>Sum Numbers with readonly field:</strong></p> <p><a href="https://stackoverflow.com/questions/3131410/adding-the-text-box-values-and-display-it-using-javascript">adding the text box values and display it using javascript</a></p> <pre><code>&lt;form name="myFormName"&gt; &lt;p&gt;&lt;input type="text" name="myInputName1" value="25.3"&gt;&lt;/p&gt; &lt;p&gt;&lt;input type="text" name="myInputName2" value="14.2"&gt;&lt;/p&gt; &lt;/form&gt; &lt;div id="total"&gt;&lt;/div&gt; &lt;script type="text/javascript&gt; var total = parseFloat(0, 10); total += parseFloat(document.myFormName.myInputName1.value, 10); total += parseFloat(document.myFormName.myInputName2.value, 10); document.getElementById("total").innerHTML = "Total is " + total; &lt;/script&gt; </code></pre> <p><strong>Round to 4 Decimal Places;:</strong></p> <p><a href="https://stackoverflow.com/a/7269919/1305169">https://stackoverflow.com/a/7269919/1305169</a></p> <pre><code>Math.round(val*10000)/10000 </code></pre> <p>Hope this helps!</p> <p>EDIT:</p> <p>You need to change your Code to the following;</p> <p><strong>Your</strong> <code>sum</code> <strong>Function:</strong></p> <pre><code>function sum() { var TotalLBCReceipts = num("TotalLBCReceipts"); var TotalKaaseReceipts = num("TotalKaaseReceipts"); var TakoradiToFactory = num("TakoradiToFactory2"); var KaaseToFactory = num("KaaseToFactory2"); var SampleResidue = num("SampleResidue"); var Sweepings = num("Sweepings"); var OrganicCocoa = num("OrganicCocoa2"); var Confiscated = num("Confiscated"); var Cuttings = num("Cuttings"); var r = document.getElementById("GRANDTOTAL1"); if (r != null) { r.value = Math.round(( TotalLBCReceipts + TotalKaaseReceipts + TakoradiToFactory + KaaseToFactory + SampleResidue + Sweepings + OrganicCocoa + Confiscated + Cuttings) * 10000) / 10000; } } </code></pre> <p><strong>And your</strong> <code>num</code> <strong>function:</strong></p> <pre><code>function num(id) { var e = document.getElementById(id); if (e != null) { return Math.round(e.value*10000)/10000; } return 0; } </code></pre> <p>You can probably just return the plain number from the <code>num</code> Function, however I show it here for completeness!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload