Roughly, this is my code:
<form name="mpform" id="mpform">
<input type="checkbox" onclick="mpfunc()" id="mpay" name="mpay[]" value="19" style="float:left;" />
//many of the above input tag - only the value changes with other numbers
</form>
<script type="text/javascript">
function mpfunc()
{
var comp=0;
document.getElementById("mpaydiv").style.visibility="visible";
for(var i=0; i< document.getElementById("mpform").elements['mpay[]'].length;i++){
if(document.getElementById("mpform").elements['mpay[]'][i].checked)
comp = comp + document.getElementById("mpform").elements['mpay[]'][i].value;
}
document.getElementById("mpaydiv").innerHTML=comp;
}
</script>
<div id="mpaydiv" style="position:fixed; right:0; visibility:hidden; bottom:0; border:1px solid black; background-color:white; padding:2px 2px;"></div></div>
</div>
<div id="footer"></div>
</div>
I have tried substituting getElementById("mpform") with form[0],mpform and others but I cant seem to access the values. With the current getelementid I get
Error: document.getElementById("mpform") is null Source File: index.php?page=fakturi Line: 3938
With mpform I get mpform is undefined as with form[0] Please help. How do I get the sum of the values of all selected checkboxes?