The form is working 100% fine but not the correct answer.
I have no idea what i can change in the script to get the right answer.
10 days x 10 taxis x 15 (price for ad) x 0.93 (100% minus discount) = 1,395
The calculator's current answer is = 1,486.05
The script was created bye jscheuer1.
The javascript
And the BodyCode:<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]; total -= fields[3]/100 * total; document.getElementById('calculate').innerHTML = "Total: " + total; } </script>
My client is driving me up the will for this calculating form.Code:<form action="#" onSubmit="calculate(); return false;"> <label>Days: <input type="text" id="el1" value="Amount of days"></label> <label>Taxis: <input type="text" id="el2" value="Amount of taxis"></label> <label>Perdiem: <input type="text" id="el3" value="Price per taxi per day"></label> <label>Discount: <input type="text" id="el4" value="100% minus % off"></label> <div id="calculate">Total:</div> <br /> <br /> <input type="submit" value="Calculate"> </form>
Please any help is appreciated.![]()



Reply With Quote

Bookmarks