• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 479
  • Last Modified:

Form not being submitted via ajax after validation (currently submitting without ajax)

The validation part of this script works, but the form is not being submitted via ajax.

Please let me know what I did wrong.

Thank you very much!

Drew


<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script> 
<script src="http://malsup.github.com/jquery.form.js"></script>


<script src="/jquery-validation/lib/jquery.js"></script>
<script src="/jquery-validation/dist/jquery.validate.js"></script>


<script>
	
$().ready(function() {
	// validate the comment form when it is submitted
	

	// validate signup form on keyup and submit
	$("#addContractForm").validate({
		rules: {

			cr_uid: {
				required: false
			},
			
			cr_issueddate: {
				required: true,
				rangelength: [10, 20]
			},
			
			cr_start: {
				required: true,
				rangelength: [10, 20]
			},
			
			cr_end: {
				required: true,
				rangelength: [10, 20]
			},
			

},
	
		messages: {
			cr_uid: "Please select a valid username",
			cr_issueddate: "Please select an issued date"
			
			        },
        
        submitHandler: function(form) {
           
                $(form).ajaxSubmit(function(){
                            url:"default.cfm",
                            type:"post",
                            success: function(){
                                       
$('#submit_add_contract').html('<img src="/img/ajax-loader1.gif" />');
           
 $('#success_contract_added').html('<div id="msg-success">Contract added</div>');
           
$('#submit_add_contract').html('<input type="submit" />');
                      }
                      
                      
                    }); 


		}



});

});

</script>

Open in new window

0
drew17
Asked:
drew17
1 Solution
 
leakim971PluritechnicianCommented:
your submitHandler code have syntax error, especially the ajaxSubmit parameter

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script> 
<script src="http://malsup.github.com/jquery.form.js"></script>
<script src="/jquery-validation/lib/jquery.js"></script>
<script src="/jquery-validation/dist/jquery.validate.js"></script>
<script>
	jQuery(function($) {
		// validate the comment form when it is submitted
		// validate signup form on keyup and submit
		$("#addContractForm").validate({
			rules: {	
				cr_uid: {
					required: false
				},
				cr_issueddate: {
					required: true,
					rangelength: [10, 20]
				},
				cr_start: {
					required: true,
					rangelength: [10, 20]
				},
				cr_end: {
					required: true,
					rangelength: [10, 20]
				}
			},	
			messages: {
				cr_uid: "Please select a valid username",
				cr_issueddate: "Please select an issued date"			
			},
			submitHandler: function(form) {
				$(form).ajaxSubmit({
					url:"default.cfm",
					type:"post",
					success: function(){
						$('#submit_add_contract').html('<img src="/img/ajax-loader1.gif" />');					
						$('#success_contract_added').html('<div id="msg-success">Contract added</div>');
						$('#submit_add_contract').html('<input type="submit" />');
					}
				}); 
			}
		});
	});
</script>

Open in new window

0
 
drew17Author Commented:
Thank you
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now