I have searched and I can see there is other questions like this, but I don't understand how to implement it.
This is my first function:
function pricecalc() {
var a = document.getElementById("field_0");
var quantity = a.value.substring(0, 1);
var b = document.getElementById("field_1");
var type = b.value;
if (quantity == '2') {
var rate = '120';
} else if (quantity == '3') {
var rate = '110';
} else {
var rate = '100';
}
var price = rate * quantity;
if (type == 'Credit card') {
var price = price * 1.034;
}
var price_each = (price / quantity);
document.getElementById("cost").innerHTML = price;
document.getElementById("costeach").innerHTML = price_each;
}
Then under it I have this:
function PHPFMG( formID ){
var redirect = 'https://www.paypal.me/' + price;
}
But I can't access the price variable in the second function. I really don't want to bodge this by setting some text on the page with the first function and then pulling it with the second function.
I looked at creating a global variable but if I set that in my top function and then pulled it in my second it only seemed to have it's original value.