Solved

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

Posted on 2013-12-31
2
475 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
[X]
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
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

Independent Software Vendors: 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!

Question has a verified solution.

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

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
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…

729 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