Get checkbox values in javascript
<p>Roughly, this is my code:</p>

<pre><code>&lt;form name="mpform" id="mpform"&gt;
&lt;input type="checkbox" onclick="mpfunc()" id="mpay" name="mpay[]" value="19" style="float:left;" /&gt;
//many of the above input tag - only the value changes with other numbers
&lt;/form&gt;
&lt;script type="text/javascript"&gt;
function mpfunc()
{
var comp=0;
document.getElementById("mpaydiv").style.visibility="visible";
for(var i=0; i&lt; 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;
}
&lt;/script&gt;
&lt;div id="mpaydiv" style="position:fixed; right:0; visibility:hidden; bottom:0; border:1px solid black; background-color:white; padding:2px 2px;"&gt;&lt;/div&gt;&lt;/div&gt;
    &lt;/div&gt;

    &lt;div id="footer"&gt;&lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>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 </p>

<blockquote>
  <p>Error: document.getElementById("mpform") is null Source File:
  index.php?page=fakturi Line: 3938</p>
</blockquote>

<p>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?</p>
