views:

40

answers:

3

I have the next code:

document.myForm.mySubmit.click();

Where myForm - form name, mySubmit - submit name. I want to call submit of my form outside me form. My problem - my form doesn't have names(terrible?). How can I do this with help of id or classes?

Or may be you know another way?

Thank you.

+2  A: 

If you give the form an "id" you can:

 var form = document.getElementById('yourIdValue');
 form.mySubmit.click();
Pointy
Thanks. This is works.
Alexander.Plutov
Now you `click` on the form? Will that submit it? I'd use the `submit` method.
Marcel Korpel
Yes. It works pretty.
Alexander.Plutov
+1  A: 

better yet you can just use the submit method. no need for the button.

var currForm = document.getElementById('yourIdValue');
currForm.submit();
guy schaller
A: 

Here is an example

$('#my_button').click(
    function()
    {
        $('#my_form').trigger('onsubmit');
        // Or 
        $('#my_form').onsubmit();
       // or 
        $('#my_form').trigger('onSubmit');
       // or  even --
        $('#my_form').submit();
    }
 );
JapanPro