Quote:
Originally Posted by chunk1978
humm... i hope not like this... as this doesn't work... for sure it's way wrong... but am i close?
-
-
function InvoiceSubTotal(form)
-
{
-
var a = (form.assignmentinvoice.value != '') ? eval(form.assignmentinvoice.value) : 0;
-
var b = (form.printinginvoice.value != '') ? eval(form.printinginvoice.value) : 0;
-
var c = (form.shippinginvoice.value != '') ? eval(form.shippinginvoice.value) : 0;
-
var total = (form.invoicesubtotal.value = a + b + c);
-
var result = num.toFixed(2);
-
form.invoicesubtotal.value = total;
-
form.invoicesubtotal.value = result;
-
}
-
-
One mistake is in the following line:
- var total = (form.invoicesubtotal.value = a + b + c);
Change that to
Also, num was only an example. Replace that with total. Why set the invoice subtotal to both total and then result. Just set it to result.
One final thing: don't use eval. Use parseFloat instead:
- var a = (form.assignmentinvoice.value != '') ? parseFloat(form.assignmentinvoice.value) : 0;
parseFloat will return NaN if not a number. In that case check using isNaN:
or you could just include it when setting a, b, and c if you like your cryptic coding!
One final, final thing is that in your original post, your html is incorrect. The Javascript goes in the head section but html comes before head like:
[HTML]<html>
<head>
...
</head>
<body>
...
</body>
</html>[/HTML]