Javascript : Submitting a form outside the actual form doesn't work
<p>I'm trying to achieve a fairly easy triggering mechanism for deleting multiple items from a tablegrid. If a user has enough access he/she is able to delete multiple users from a table. In the table I have set up checkboxes, one per row/user. The name of the checkboxes is <code>UsersToDeletep[]</code>, and the value per row is the unique UserID.</p>

<p>When a user clicks the button 'Delete selected users' a simple validation takes place to make sure at least one checkbox is selected. After that I call my simple function <code>Submit(form)</code>. The function works perfectly when called within the <code>form</code>-tags, where I also use it to delete a single user.</p>

<p>The function:</p>

<pre><code>function Submit(form)
{   
    document.forms[form].submit();
}
</code></pre>

<p>I've also alerted <code>document.forms[form]</code>. The result is, as expected <code>[object HTMLFormElement]</code>. But for some reason the form just won't submit and a pagereload takes place. I'm a bit confused and can't seem to figure out what I'm doing wrong.</p>

<h3>Update</h3>

<p>As requested: the calling-code:</p>

<p>The code placed within 'onclick="javascript:"':</p>

<pre><code>if(CheckMinimumCheckedCheckboxes('FormUserList', 1) == true)
{ 
    if(confirm('Weet u zeker dat u de geselecteerde gebruiker(s) wilt verwijderen?')) 
    { 
        Submit('FormUserList'); 
    } 
} 
else 
{ 
    alert('U dient minimaal 1 gebruiker te selecteren welke u wilt verwijderen.'); 
}
</code></pre>

<p>Seperate functions in an external JS-file.</p>

<pre><code>function CheckMinimumCheckedCheckboxes(formName, minAmount)
{
    var totalChecked = 0;
    var totalElements = document.forms[formName].length;

    for(i = 0; i &lt; totalElements; i++)
    {
        if(document.forms[formName][i].checked == true)     
        {
            totalChecked++;
        }
    }

    if(totalChecked &gt;= minAmount)
    {
        return true;
    }

    return false;
}

function Submit(form)
{   
    document.getElementById(form).submit();
}
</code></pre>
