I have a JavaScript code that performs mathematical calculations, and I need to extract the final result to include it in a form. My plan was to utilize an
<input type="hidden" name="new total">
field to store this result. I am looking to retrieve the information from the "New Total" field. You can view my JavaScript code in action here: http://jsfiddle.net/danielrbuchanan/yjrTZ/5/
var prices = [];
function remove(arr, itm){
var indx = arr.indexOf(itm);
if (indx !== -1){
arr.splice(indx, 1);
}
}
function calculateSelectedDues(checkbox, amount) {
if (checkbox.checked === true) {
prices.push(amount);
} else {
remove(prices, amount);
}
var total = 0;
for (var i = 0, len = prices.length; i < len; i++)
total += prices[i];
var min = prices.slice().sort(function(a,b){return a-b})[0];
if(typeof min === 'undefined') min = 0;
var withDiscount = total - min;
var discountAmount = withDiscount - total;
//document.grad_enroll_form.total.value = total;
document.querySelector("#value").innerHTML = "Total: $"+total+'<br>';
document.querySelector("#value").innerHTML += "Discount: $"+discountAmount+'<br>';
document.querySelector("#value").innerHTML += "New total: $"+withDiscount+'<br>';
}
Although it appears straightforward, I seem to be struggling to figure it out.