?
Solved

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

Posted on 2013-12-31
2
Medium Priority
?
476 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 2000 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
Suggested Courses

762 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