Javascript : Submitting a form outside the actual form doesn't work

Posted by Ben Fransen on Stack Overflow See other posts from Stack Overflow or by Ben Fransen
Published on 2010-05-03T13:04:32Z Indexed on 2010/05/03 13:08 UTC
Read the original article Hit count: 361

Filed under:

Hello all,

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 UsersToDeletep[], and the value per row is the unique UserID.

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 Submit(form). The function works perfectly when called within the form-tags, where I also use it to delete a single user.

The function:

function Submit(form)
{   
    document.forms[form].submit();
}

I've also alerted document.forms[form]. The result is, as expected [object HTMLFormElement]. 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.

Can anyone point me in the right direction?

Thanks in advance!

Ben

© Stack Overflow or respective owner

Related posts about JavaScript