0

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!'); }

1
  • I have solved the above whereby the form now does give a response and it validates first time. However, now whats happening is the form is submitting whether the form is validated or not. So the fields that need validating are comign up as red AND the form is submitting and giving the response. The amended code is below. Commented Nov 20, 2009 at 10:49

1 Answer 1

1
$(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!'); 
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.