0

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.

djdd87
68.7k29 gold badges160 silver badges198 bronze badges
asked Sep 2, 2010 at 12:50
1
  • show some concise version of the code Commented Sep 2, 2010 at 12:52

3 Answers 3

2

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

 var form = document.getElementById('yourIdValue');
 form.mySubmit.click();
answered Sep 2, 2010 at 12:51
Sign up to request clarification or add additional context in comments.

1 Comment

Now you click on the form? Will that submit it? I'd use the submit method.
1

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

var currForm = document.getElementById('yourIdValue');
currForm.submit();
answered Sep 2, 2010 at 12:56

Comments

0

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();
 }
 );
answered Sep 2, 2010 at 12:58

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.