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.
eg
text field v1+text field v2+text field v3=text field result
the text field should accept on four decimal numbers or automatically turn numbers to four decimal place.
I am using the following sum function;
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;
}
}
And grabbing the Values using;
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;
}
thanks.