0

Trying to recalculate final price if discount's redeemed. All seems to works fine, but the price doesn't get recalculated, here's what I get in console log - Uncaught TypeError: Cannot set property 'textContent' of null. is it because there is multiple stuff stacked in if statement?

  var disc = "WE56DQ1";
  var redeem = 20;
  var totalValue = this.totalCart - (this.totalCart*redeem/100);
  var coupon = disc.trim();
  var input = document.getElementById('discount').value;
  if (input.toUpperCase() == coupon.toUpperCase()) {
    document.getElementById('total-cart').textContent = totalValue.toFixed(2);
    document.getElementById('message').innerHTML = "Discount applied!";
    document.getElementById('err').innerHTML = "";
    return true;
  } else {
    document.getElementById('err').innerHTML = "Invalid discount";
    document.getElementById('message').innerHTML = "";
    return false;
  }
}```
  • Is your ` – Sebastian Simon Aug 02 '20 at 20:24
  • I recommend creating a CodePen or something similar so we can see the issue for ourselves. – David Tran Aug 02 '20 at 20:27
  • @DavidTran A CodePen is less helpful here, as it automatically handles script wrapping, which is likely the thing that fails here. Off-site code also doesn’t meet the criteria of a [mre]. – Sebastian Simon Aug 02 '20 at 20:49
  • here's the code https://codepen.io/adamleniak/pen/WNwebzv – Ciprian Jîjie Aug 02 '20 at 20:57
  • I tried to use the codepen to understand the issue, but it doesn't seem to work, at all. As @user4642212 pointed out, it might not be possible to reproduce the issue with codepen. – David Tran Aug 02 '20 at 23:52

0 Answers0