Same question more else if() statements causes it to stop working.
I'm building a custom order form for my ad agency where the user selects the items they want from a form checkbox and the subtotal/order summary table below updates accordingly. The client is required to get at least the base spot which is $1125, while the four secondary spots are optional and are $450. If the client decides to get extra[s], then the trafficking cost also goes up ($75 each).
Everything works properly until i get to the highest amount, and then then the table doesn't update properly.
updated fiddle with full problem: http://jsfiddle.net/joelslevy21/5v8Ltkxf/3/
updated script:
if ( totalFinal == "3,330" ) {
$('#companion').css("display","block");
$('#quantityCompanion').text("4");
$('#subTotalCompanion').text("$1,800");
$('#quantityTrafficking').text("5");
$('#subTotalTrafficking').text("$375");
} else if ( totalFinal == "2,775" ) {
$('#companion').css("display","block");
$('#quantityCompanion').text("3");
$('#subTotalCompanion').text("$1,350");
$('#quantityTrafficking').text("4");
$('#subTotalTrafficking').text("$300");
} else if ( totalFinal == "2,250" ) {
$('#companion').css("display","block");
$('#quantityCompanion').text("2");
$('#subTotalCompanion').text("$900");
$('#quantityTrafficking').text("3");
$('#subTotalTrafficking').text("$225");
} else if ( totalFinal == "1,725" ) {
$('#companion').css("display","block");
$('#quantityCompanion').text("1");
$('#subTotalCompanion').text("$450");
$('#quantityTrafficking').text("2");
$('#subTotalTrafficking').text("$150");
} else {
$('#companion').css("display","none");
$('#quantityTrafficking').text("1");
$('#subTotalTrafficking').text("$75");
}
.getElementsByClassName()over and over again isn't good - why wouldn't you just use$('.final').each(...)?.getElementsByClassName(), but the browser has to work at it so doing it afresh with every iteration of the loop just to get a single element is terribly inefficient. Since you're already using jQuery, you might as well go all-in. All I did was move the JavaScript to the body (jsfiddle setting) and add a "quantity" element to the page because it was missing.function orderSummary()inside yourfunction calculate()andwhile(init = document.getElementsByClassName("final")[i++]) {?