JQuery - How to call $ ('# myForm'). Submit (function ()

how can i call this function without using the submit form?

$('#myForm').submit(function() { .... 
+8
jquery submit triggers
source share
6 answers

You can try -

 $('#myForm').trigger('submit'); 

Working demo - http://jsfiddle.net/ipr101/KvwMb/1/

+21
source share

You can directly use something like this

 $('#button1').click(function(){ $('#search').submit(); }); 

Or you can use it from any javascript code. Which will call your function code $('#myForm').submit(function(){.....

+2
source share
 return false; 

adding this to the function will stop submitting the form.

Or, if you want to call a function in another event, put the function in the corresponding event handler (the submit button is not pressed?)

+1
source share
 <input type="button" id="btn" value="click"> 

jquery

  $(function(){ $('#myForm').submit(function() { ....}); $("#btn").click(function(){ $('#myForm').trigger('submit'); }); }); 
0
source share

You will have to dig it out of the DOM data. But let me tell you, this is not recommended. Try it,

 var form = $('#myForm'); var data = form.data(); var events = data.events; 

If a handler function is attached to the submit form, it will be present as

 var submit_list = events.submit; 

Now, if all goes well, at best you can get submit_list as a list of all handler objects attached to submit the form event.

Shortcut: Assuming you have one and only one handler attached to dispatch an event for #myForm ,

 $('#myForm').data().events.submit[0].handler 

is your function.

Play with data() , but remember that this is not recommended. Happy coding.

0
source share

Extract code from the callback to the function and call it when necessary.

-one
source share

All Articles