Click here to Skip to main content
15,885,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a shopping cart that allows users to select their desired items using a checkbox. The values show but the total does not increase.
JavaScript
<pre>function subTotalEntry() {
  let total = document.getElementById('entryTotal');

  let price = document.querySelector('.first-entry').innerHTML;
  
  let qty = document.querySelector('.entryQty').checked;
    
  let cageSize = document.querySelector('.firstCageSize').value;
  
  let smCagePrice = document.querySelector('.small-cage').innerHTML;
  
  let lrgCagePrice = document.querySelector('.large-cage').innerHTML;
  
  if (qty && cageSize == 'small') {
      total.value = Number(price) * Number(qty) + Number(smCagePrice);
  } else if (qty && cageSize == 'large') {
      total.value = Number(price) * Number(qty) + Number(lrgCagePrice);
  } else if (qty && cageSize == 'BYO') {
      total.value = Number(price) * Number(qty);
  } else {
      total.value = Number(price) * Number(qty);
  }
  console.log(total.value);
  grandTotal();

}


What I have tried:

I have tried adding the Number(total.value) to each if statement but the values only increase incorrectly and does not decrease.
Posted
Updated 5-Dec-22 17:32pm
Comments
Sandeep Mewara 5-Dec-22 23:28pm    
You need to share more details on what are you trying to achieve here.
Chris Copeland 6-Dec-22 4:53am    
Have you tried debugging the code in the developer tools, stepping through the code line-by-line and seeing what each of the values are?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900