Link to home
Start Free TrialLog in
Avatar of karthik80c
karthik80cFlag for United States of America

asked on

Jquery form submit not working ?

Hi Experts ,

We trying to submit a form via Jquery but it's not happening . When checking in console window function returning form as a object . Please see the attached screenshot

Code :$("#educationMyForm").submit();

User generated image
Avatar of Mukesh Yadav
Mukesh Yadav
Flag of India image

Try this ;)

$("#educationMyForm")[0].submit();
Avatar of karthik80c

ASKER

Hi Mukesh

Throws Uncaught TypeError: $(...)[0].submit is not a function(…)
ASKER CERTIFIED SOLUTION
Avatar of Kim Walker
Kim Walker
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the info @Kim Walker . It's Works . Please tell the reason . So that I can easily remember
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
All the input elements in your form are sub-elements of the form in the DOM. If you have a form named "myform" with an element named "address", the DOM path to that element is document.myform.address.

The form prototype, and thereby all forms, contain a method called "submit" which gathers all the values of the sub-elements and sends them to the server for processing. The DOM path to the submit method is document.myform.submit(). Because it is a method, it is followed by a set of parentheses. However, if you add an input element named "submit" to the form, the path to that element becomes document.myform.submit and replaces the method at document.myform.submit().

Although the form can still be submitted by the natural behavior of a submit button, any attempt to submit the form otherwise by the submit() method will invoke an error. If you invoke the preventDefault() method to override the submit button's natural behavior, the form cannot be submitted at all.

A similar situation occurs in jQuery where the jQuery object's prototype submit method will be replaced by the submit input element.
Thanks @Kim Walker For detailed Explanation