Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2013-12-31
2
471 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
ID: 39749720
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
ID: 39750521
Thank you
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

792 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