Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Change value based on Closure Counter in JavaScript

How to change the Total price value based on No. of boxes value.

the code I tried

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

function NegboxENtryValue() {
  let inputval = document.getElementsByClassName("boxENtryValue")[0].value
  let prodPrice = document.getElementById("productTotalPrice").innerHTML.split(/[\s&]+/)
  prodPrice[1] = prodPrice[1] / inputval
  document.getElementById("productTotalPrice").innerHTML = `Rs. ${prodPrice[1]} /-`
}

function PosboxENtryValue() {
  let inputval = document.getElementsByClassName("boxENtryValue")[0].value
  let prodPrice = document.getElementById("productTotalPrice").innerHTML.split(/[\s&]+/)
  prodPrice[1] = prodPrice[1] * inputval
  document.getElementById("productTotalPrice").innerHTML = `Rs. ${prodPrice[1]} /-`
}

where boxENtryValue is the value of no. of boxes. its working, but when decrease to 1, the value doesnt change, still on x2 value.

Note: Total price should be multiplication or division of Price/Box

>Solution :

  function NegboxENtryValue() {
         let inputval = document.getElementsByClassName("boxENtryValue")[0].value
         let prodPrice = document.getElementById("productPrice").innerHTML.split(/[\s&]+/) // here use product price not product total price
         prodPrice[1] = prodPrice[1] * inputval
         document.getElementById("productTotalPrice").innerHTML = `Rs. ${prodPrice[1]} /-`
       }

function PosboxENtryValue() {
      let inputval = document.getElementsByClassName("boxENtryValue")[0].value
      let prodPrice = document.getElementById("productPrice").innerHTML.split(/[\s&]+/) // here use product price not product total price
      prodPrice[1] = prodPrice[1] * inputval
      document.getElementById("productTotalPrice").innerHTML = `Rs. ${prodPrice[1]} /-`
    }

Please use product price in the calculation.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading