Combustion
07-06-2004, 12:10 PM
I have a question which has had me stumped for a few days now. I have a form that I add the values of fields together and display the total in a total field. I have the calculations working correctly. My problem is that I would like to change the format of the total from 1234567 to 1,234,567 . Is this possible using javascript? Here is the code that I use to do the calculations. I have edited out all the code that I use to validate the fields because I don't think it is needed for this question.
Thanks in advance.
function calculateTotal(){
var fields=Array("life1","life2","life3","life4","life5","life6");
for(i=0;i<fields.length;i++){
str="var val"+i+"=parseInt(document.frmLifeNeed."+fields[i]+".value);";
eval(str);
}
total=val0+val1+val2+val3+val4-val5
document.frmLifeNeed.total.value = total;
}
Thanks in advance.
function calculateTotal(){
var fields=Array("life1","life2","life3","life4","life5","life6");
for(i=0;i<fields.length;i++){
str="var val"+i+"=parseInt(document.frmLifeNeed."+fields[i]+".value);";
eval(str);
}
total=val0+val1+val2+val3+val4-val5
document.frmLifeNeed.total.value = total;
}