Hi there,
Wondering if anyone can help me..... I am trying to do a simple calculation with 2 sets of radio buttons and one checkbox. The total cost needs to be the values of service "multiply by" car "plus" other.... the "other checkbox needs to be an optional.. I am just starting and cant seem to get it to work!! Any help would be appreciated. Cheers!
//Calculate and display the total cost of the selected services
function calculateCost() {
var radioButton; //A radio button
var cost = 0; //Cost of the selection
//add up the costs of the selected
for (var i= 1; i<= 9; i++) {
radioButton = document.getElementById ("service" + i);
if (radioButton.checked ==true) {
cost += parseInt (service.value) * parseInt(car.value) + parseInt(other.value);
if(cost == null){ //if cost is equal to null, a button HAS been not been checked
alert("Please check a radio buttton")
}
//Display the total cost of the selected services
alert ("The approximate cost is $" + cost);
}
</script>
</head>
<h2>Larry's Limousine Service</h2>
<p>Complete the form below for a quote on our limousine service.</p>
<form>
<p>Service required:</p>
<p><input type="radio" id="service1" name="service" value="50" /> <label for="service1">City to airport</label><br/>
<p><input type="radio" id="service2" name="service" value="50" /> <label for="service2">Airport to city</label><br/>
<p><input type="radio" id="service3" name="service" value="75" /> <label for="service3">Prom</label><br/>
<p><input type="radio" id="service4" name="service" value="100" /> <label for="service4">Wedding</label><br/>
<p><input type="radio" id="service5" name="service" value="90" /> <label for="service5">Other special event</label></p>
<p> </p>
<p>Car Required:</p>
<p><input type="radio" id="car1" name="car" value="1"/> <label for="car1">Luxury Sedan</label><br/>
<p> <input type="radio" id="car2" name="car" value="2"/> <label for="car2">6 passenger stretch limousine</label><br/>
<p><input type="radio" id="car3" name="car" value="2.5"/> <label for="car3">8 passenger stretch limousine</label><br/>
<p><input type="radio" id="car4" name="car" value="3"/> <label for="car4">10 passenger stretch limousine</label></p>
<p> </p>
<p><label for="other">Click here if your party includes more than 3 passengers: </label><input type="checkbox" id="other" name="ex_people" value="25"/></p>
<p><input type="Submit" value="Calculate" onClick="calculateCost();" /> <input type="reset"/></p>
</form>
</body>
</html>