Eddie Madrigal
Eddie Madrigal

Reputation: 9

Why does my shopping cart total not work using onclick and toggle?

Here is a link to my problem-child shopping cart: http://CODEX32.com/simpleShoppingCart with a link to view its page source at the top left portion of the page.

The specific issue is that the running total is not working properly. Any direction would be extremely appreciated. Thank you in advance.

try {
function grandTotal() {     
running_total = window.sku9448Total + window.sku2976Total;
document.getElementById('total').value = '$' + running_total;
}
} catch(e) {}

Upvotes: 0

Views: 149

Answers (1)

Bardh Lohaj
Bardh Lohaj

Reputation: 1410

Doing a consol.log(window.sku2976Total) revealed window.sku2976Total is undefined.

Your problem is that the variables are not defined at the moment that you are trying to access them so the result leads to undefined variable shown as NaN when appended.

So, either set the variables in the beginning to 0 or check if the variables are defined before using them.

You can do it like:

if(typeof variable_here === 'undefined'){
   // your code here.
};

or

if(! variable_here){
   // your code here.
};

Upvotes: 1

Related Questions