Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
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

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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!