Quote:
Originally Posted by jmrker
What have you attempted thus far?
|
Basically its a fuel calculator. User selects fuel from a drop down list then enters the quantity they want into a textbox. This value is then selected as either litres or gallons using the radio buttons. Default value is litres radio button. If user selects gallons I want to multiply the litres value by 4.54.
User will also use a second set of radio buttons to choose which currency they want their fuel total to be displayed in.
I have this so far
Code:
window.onload = startForm;
function startForm() {
document.forms[0].fuel.focus();
document.forms[0].fuel.onchange = calcTotals;
document.forms[0].litres.onblur = calcTotals;
document.forms[0].unit.onclick = calcTotals;
document.forms[0].currency.onclick = calcTotals;
function calcTotals() {
// select fuel(price)
var product = document.forms[0].fuel;
var pIndex = product.selectedIndex;
var productPrice = parseFloat(product.options[pIndex].value);
// select quantity(litres)
var quantityChosen = parseFloat(document.forms[0].litres.value);
//var fuelUnit = document.forms[0].litre;
finalPrice = productPrice * quantityChosen;
// get subtotal(final price - tax)
var subVal = finalPrice / 1.23;
document.forms[0].sub.value = (subVal).toFixed(2);
var taxRate = 0.23; //23%
var taxVal = finalPrice - subVal;
document.forms[0].tax.value = (taxVal).toFixed(2);
// get total price(subtotal + tax)
document.forms[0].tot.value = finalPrice.toFixed(2);
}
Any help would be much appreciated and I thank you for your reply.