I have some JS variables inside a Blade file which is a checkout page. In this checkout page, there is a cart summary with some informations about the product that is being purchased that are retrieved from a form in the previous page with Laravel sessions. In the checkout page I proceed to declare some JS variables to perform some basic calculations like cart total.
I also have a form with the order information, shipping and such, and I need to store the cart total inside this form. So I would need to save the total (the variable costoTotale) that has been calculated and save it as a value=”” inside an input. Is there a way I can do it?
This is my script tag with the variables:
` var costoIniziale = {{session('prezzo')}} * {{session('quantity')}};
var costoSpedizione = costoIniziale + {{session('spedizione')}};
var IVA = ((costoSpedizione * 1.22) - costoSpedizione).toFixed(2);
var costoTotale = (costoSpedizione * 1.22).toFixed(2);
`
What I have tried so far is to do this:
` function total() {
(costoSpedizione * 1.22).toFixed(2);
}
function getMyTotal() {
document.getElementById('totaleLordo').setAttribute('value', total());
}
With “totaleLordo” being the ID of my hidden input, but it doesnt’ work.