views:

375

answers:

1

I had both the validation and the ajaxform working fine alone, but when I try to combine the form doesn't work properly. I am not that familiar with JQuery and so think the syntax is wrong somewhere. Can anyone spot what Im doing wrong?

The form takes two attempts before it validates, and then the form sends but does not give any response.

// prepare the form when the DOM is ready $(document).ready(function() { var options = { target: '#output1', // target element(s) to be updated with server response beforeSubmit: showRequest, // pre-submit callback success: showResponse // post-submit callback };

// bind form using 'ajaxForm' $('form#webcheck').ajaxForm(options); });

function showRequest(){ $("form#webcheck").validate(); jQuery.validator.messages.required = jQuery.validator.messages.email = ""; jQuery.validator.messages.required = jQuery.validator.messages.telephone = ""; jQuery.validator.messages.required = jQuery.validator.messages.name = ""; }

function showResponse(){ alert('Thanks for your comment!'); }

A: 
$(document).ready(function() { 
 var options = { 
  //target:        '#response',   // target element(s) to be updated with server response 
  beforeSubmit:  showRequest,  // pre-submit callback 
  success:       showResponse  // post-submit callback 
 }; 

 // bind form using 'ajaxForm' 
 $('form#webcheck').ajaxForm(options); 
}); 

function showRequest(){ 
 jQuery.validator.messages.required = jQuery.validator.messages.email = "";
 jQuery.validator.messages.required = jQuery.validator.messages.telephone = "";
 jQuery.validator.messages.required = jQuery.validator.messages.name = "";
 $("form#webcheck").validate().form();

}

function showResponse(){ 
    alert('Thanks for your comment!'); 
}
leanne4000