I have this calculating form works extremely well for my client up some one went and put in to the percentage box 0.93 and it showed to wrong amount.
In the website: 10 x 10 x 15 x 0.93 = 13.95
Has to be: 10 x 10 x 15 x 0.93 = 1.395
I have no idea what to change in the javascript to get the full stop in the right place
This is the script.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<script type="text/javascript">
function calculate() {
var fields = [], i = 1, el, val, whole, total;
for (i; i < 5; ++i) {
el = document.getElementById('el' + i); val = el.value;
if((whole = i < 3) && /\./.test(val) || isNaN(Number(val))) {
alert("Please enter only " + (whole? 'whole ' : '') + "numbers\nfor " + (el.value = el.defaultValue));
el.focus();
el.select();
return;
}
fields.push(val);
}
total = (fields[0] * fields[1] * fields[2])*fields[3]/100;
document.getElementById('calculate').innerHTML = "Total: " + total;
}
</script></head>
<body>
<form action="#" onSubmit="calculate(); return false;">
<label>Days: <input type="text" id="el1" value="10"></label>
<label>Taxis: <input type="text" id="el2" value="10"></label>
<label>Perdiem: <input type="text" id="el3" value="15"></label>
<label>Discount: <input type="text" id="el4" value="93"></label>
<div id="calculate">Total:</div>
<br />
<br />
<input type="submit" value="Calculate">
</form>
</body>
</html>
I will appreciate any help with this.
Thanks
Have you tried using:
total = (fields[0] * fields[1] * fields[2])*fields[3]/1000instead of:
total = (fields[0] * fields[1] * fields[2])*fields[3]/100