View Single Post
Old 09-25-2012, 03:35 PM   PM User | #3
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
you have 3 separate sections - flights, return ticket and seat class. But you only ever loop though the flights. You need to collect values for of all of them, multiply them at the end and then display the result. If you are going to submit this as homework you should study it to see how it works...

Code:
function calculateCost() { 

for (var i = 1; i < 7; i++) { 
var radiobutton = document.getElementById("flight" + i); 
if (radiobutton.checked == true) { 
var base=radiobutton.value;
		}
	}
var rtn=document.getElementById("returnfare").checked?2:1; 
for (var a = 1; a < 4; a++) { 
var radiobutton = document.getElementById("seating" + a); 
if (radiobutton.checked == true) { 
var seatclass=radiobutton.value;
		}
	}
var cost=base*rtn*seatclass;
alert("The selected flight will cost $" + cost); 
}
xelawho is offline   Reply With Quote
Users who have thanked xelawho for this post:
Lana1993 (09-26-2012)