php text field turns numbers into decimals
<p>l need help to finish my php project.
l will like to have a text fields V1,V2,V3 and result/output to accept only decimal numbers (4 decimal place ie 0.0000) or automatically turns numbers to four decimal pace and have a read-only field generate the total sum of the 3 text fields without reloading the form. </p>

<p>eg
<code>text field v1+text field v2+text field v3=text field result</code></p>

<p>the text field should accept on four decimal numbers or automatically turn numbers to four decimal place.</p>

<p>I am using the following sum function;</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 = TotalLBCReceipts + 
                   TotalKaaseReceipts + 
                   TakoradiToFactory +
                   KaaseToFactory +
                   SampleResidue +
                   Sweepings +
                   OrganicCocoa +
                   Confiscated+Cuttings;
     }
}
</code></pre>

<p>And grabbing the Values using;</p>

<pre><code>function num(id) 
{
    var e = document.getElementById(id);

    if (e != null) 
    {
        var v = e.value;
        if (/^\d+$/.test(v)) 
        {
            return parseInt(v, 10);
        }
    }

return 0;

}
</code></pre>

<p>thanks.</p>
