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.