1// jQuery ajax form submit example, runs when form is submitted
2$("#myFormID").submit(function(e) {
3 e.preventDefault(); // prevent actual form submit
4 var form = $(this);
5 var url = form.attr('action'); //get submit url [replace url here if desired]
6 $.ajax({
7 type: "POST",
8 url: url,
9 data: form.serialize(), // serializes form input
10 success: function(data){
11 console.log(data);
12 }
13 });
14});
1// It is simply
2$('form').submit();
3
4// However, you're most likely wanting to operate on the form data
5// So you will have to do something like the following...
6$('form').submit(function(e){
7 // Stop the form submitting
8 e.preventDefault();
9 // Do whatever it is you wish to do
10 //...
11 // Now submit it
12 // Don't use $(this).submit() FFS!
13 // You'll never leave this function & smash the call stack! :D
14 e.currentTarget.submit();
15});
1$('#button1').click(function(){
2 $('#formId').attr('action', 'page1');
3});
4
5
6$('#button2').click(function(){
7 $('#formId').attr('action', 'page2');
8});
9
1$(document).ready(function(){
2 $("#submitBtn").click(function(){
3 $("#myForm").submit(); // Submit the form
4 });
5});
1<input type='button' value='Submit form' onClick='submitDetailsForm()' />
2
3<script language="javascript" type="text/javascript">
4 function submitDetailsForm() {
5 $("#formId").submit();
6 }
7</script>
8