I have a form that customers input the quantity they want of an item and submit the form to me, and I receive it in an email…
It calculates the total per line, and then the total for the order, but I do not have it calculating all of these fields in a currency format.
I am trying to make it so when the fields are updated, they are converted from 1000.5 to $1,000.50
I know nothing about java script, I am just using code I find and trying to make it work to what I need…
[CODE]<SCRIPT LANGUAGE=”JavaScript”>
function formatCurrency(num) {
num = num.toString().replace(/$|,/g,”);
if(isNaN(num))
num = “0”;
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = “0” + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+’,’+
num.substring(num.length-(4*i+3));
return (((sign)?”:’-‘) + ‘$’ + num + ‘.’ + cents);
}
</script>
<script language=”Javascript”>
function computeAdd90055 (obj) {
obj.res90055.value = eval (obj.val90055.value) *
eval (obj.val90055p.value);
}
function computeAdd21903 (obj) {
obj.res21903.value = eval (obj.val21903.value) *
eval (obj.val21903p.value);
}
function computeAdd90795 (obj) {
obj.res90795.value = eval (obj.val90795.value) *
eval (obj.val90795p.value);
}
function computeAddTotal (obj) {
obj.total.value = eval (obj.res90055.value) +
eval (obj.res21903.value) +
eval (obj.res90795.value);
}
</script>
</head>
<body>
<form>
5-9005: <input type=”text” name=”val90055″ value=”0″ onchange=”computeAdd90055(this.form);computeAddTotal(this.form);”> <br>
Cost: $<input type=”text” name=”val90055p” value=”56.33″> <br>
Total Line Cost: $<input type=”text” value=”0″ name=”res90055″><br><br>
3-2190: <input type=”text” name=”val21903″ value=”0″ onchange=”computeAdd21903(this.form);computeAddTotal(this.form)”> <br>
Cost: $<input type=”text” name=”val21903p” value=”51.32″> <br>
Total Line Cost: $<input type=”text” value=”0″ name=”res21903″><br><br>
5-9079: <input type=”text” name=”val90795″ value=”0″ onchange=”computeAdd90795(this.form);computeAddTotal(this.form)”> <br>
Cost: $<input type=”text” name=”val90795p” value=”55.95″> <br>
Total Line Cost: $<input type=”text” value=”0″ name=”res90795″> <hr>
Total: $<input type=”text” name=”total” onBlur=”this.value=formatCurrency(this.value);”>
</form>
Currently as it stands, if I clicked inside of the total box, and then clicked out of it, the conversion would happen… how to I make it so when this box is populated with numbers, this happens automatically?