function g_Ticket(ticketAmount) {
var outOfStock = false;
if (q_sold >= group_available) {
alert("Tickets sold out. Sorry.");
return;
}
for (var g = 1; g <= ticketAmount; g++) {
// loop through # of tickets to see if sold out
q_sold++;
if (q_sold >= group_available) {
if (g < ticketAmount) {
alert("You can only buy " + g + " tickets... Sorry.");
outOfStock = true;
break;
}
}
}
if (!outOfStock) {
alert("Thank you. We have " + (group_available - q_sold)+ " tickets left.");
document.getElementById('groupTicket').value = 0;
}
}
//the above code works fine apart from the one below.
var total = 0;
var ticketPrices = {
adultFare: 10,
childrenFare: 5,
groupFare: 20
};
document.getElementById('ticketAmount').onclick = function() {
var type = document.getElementById('g_total').value;
var price = ticketPrices[type];
total *= price;
document.getElementById('groupTicket').innerHTML = total;
};
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.