Solved

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

Posted on 2013-12-31
2
464 Views
Last Modified: 2014-01-01
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
Comment
Question by:drew17
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
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
 

Author Closing Comment

by:drew17
Comment Utility
Thank you
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now