$.validator.setDefaults({ submitHandler: function() { //$("#contactForm").ajaxSubmit(); //alert("Thank you. You will receive a confirmation email shortly."); $("#contactForm").ajaxSubmit({ success: function(t) { //alert("Form submission a success. The server has returned: " + t); $("#formContainer").html('
' + t + '
'); } }); } }); $(document).ready(function() { // validate contact form when submit button keyup $("#contactForm").validate({ rules: { company: "required", name: { required: true, minlength: 2 }, message: { required: true }, email: { required: true, email: true } }, messages: { company: { required: "Please enter your company name" }, name: { required: "Please enter your name", minlength: "Your name must be at least 2 chars" }, message: { required: "Please enter a message" }, email: "Please enter a valid email address" } }); // apply inline-box only for mozilla if( jQuery.browser.mozilla ) { // do when DOM is ready $( function() { // search form, hide it, search labels to modify, filter classes nocmx and error $( '#contactForm' ).hide().find( 'p>label:not(.nocmx):not(.error)' ).each( function() { var $this = $(this); var labelContent = $this.html(); var labelWidth = document.defaultView.getComputedStyle( this, '' ).getPropertyValue( 'width' ); // create block element with width of label var labelSpan = $("") .css("display", "inline") .width(labelWidth) .html(labelContent); // change display to mozilla specific inline-box $this.css("display", "-moz-inline-box") // remove children .empty() // add span element .append(labelSpan); // show form again }).end().show(); }); }; });