I am facing a challenge in passing a JavaScript variable through a hidden form to a PHP script. While I have no issue passing it to PHP, I am struggling to integrate the variable into the form.
function calculate() {
var radio1 = document.forms["calcForm"].v1;
var radio2 = document.forms["calcForm"].v2;
var getf1 = getSelectedRadio(radio1);
var getf2 = getSelectedRadio(radio2);
var f1 = radio1[getf1].value;
var f2 = radio2[getf2].value;
var resultat = document.getElementById("resultat");
var total = (parseInt(f1) + parseInt(f2)).toFixed(0);
resultat.value = total; //used to show value in another input-field
}
document.contactForm.formTotal.value = total;
The issue arises with the last line as it does not accept `total`. The `calculate` function works flawlessly - as does everything else when I substitute `total` with a simpler variable like `var x= 10;`
I am looking for a solution to set `document.contactForm.formTotal.value` to the value of `total`. It seems that there might be difficulty retrieving some values from the function, but my knowledge of JavaScript is limited, hindering me from finding a resolution.