The page I'm currently working is a dashboard for an online publisher. The way it works is that it uses a foreach loop to create an instance of an editor form for each article. What I'm trying to do is add checkboxes to each instance that can add a value to a subtotal at the bottom of the page. I can only get it to work if the output is contained within the same form.
So my question actually is: Is there a way to to use inputs from multiple forms and return a single output?
Simplified PHP code for each instance:
foreach ($Articles as $idx => $Article){
echo <form action='/gatekeeper.php' method='POST' target='_SAVE{$Article["ID"]}' onchange='submit()'>
echo <input type="checkbox" onClick="checkTotal()" />
}
And here is the JavaScript code.
function checkTotal() {
document.listForm.total.value = '';
var sum = 0;
for (i=0;i<document.listForm.choice.length;i++) {
if (document.listForm.choice[i].checked) {
sum = sum + parseInt(document.listForm.choice[i].value);
}
}
document.listForm.total.value = sum;
}