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

82
Views
Three alerts in a function and only the first Function works more than once

Here's my javascript code:

function getMediaPrice() {
    var mediaTypeValue = document.getElementById("media-type").value;
    var mediaBrandValue = document.getElementById("media-brand").value;
    var mediaProductValue = document.getElementById("media-product").value; 
    mediaQty = document.getElementById("media-qty").value;
    alert(mediaQty)
    var filteredArrayOfValues = filteredMediaPrice.filter(function(r){
      return r[0] === mediaTypeValue && r[1] === mediaBrandValue && r[2] === mediaProductValue 
    });
     alert(filteredArrayOfValues)
    filteredMediaPrice =  Number(filteredArrayOfValues.reduce((amount, r) => amount + r[16], 0)).toFixed(2);
    alert(filteredMediaPrice)
    calculatedMediaTotal = filteredMediaPrice.toFixed(2);
    alert(calculatedMediaTotal)
    document.getElementById("media-price").innerHTML = 'Media Price: £' + calculatedMediaTotal;
    document.getElementById("media-total-price").innerHTML = 'Media Total Price: £' + calculatedMediaTotal + ' + VAT';
  }

Is there a reason why the first alert alert(mediaQty) works every time the mediaQty dropdown list changes but alert(filteredArrayOfValues) and alert(calculatedMediaTotal) only work once?

I've been stuck on this for hours and can't work it out.

about 4 years ago · Juan Pablo Isaza
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!