karlelizabeth
karlelizabeth

Reputation: 167

clear a form without refresh

am working with a form that has recaptcha and its validated with jquery, everything works perfectly fine *the info is sent to my email and all required field are checked before been send)

the only one problem am facing is that once the info is sent and all fields are reset the error messages are visible only way they are hidden is if page is i change in the js "reset" instated of "clear" but this refresh the pagge and the thank u message isnt visible anymore.

(i know maybe all sounds bit confiusing) this is the code what am talking

function validateCaptcha(){
    challengeField = $("input#recaptcha_challenge_field").val();
    responseField = $("input#recaptcha_response_field").val();
    nameField = $("input#name").val();
    emailField = $("input#email").val();
    phoneField =$("input#phone").val();
    reasonField =$("input#reason").val();
    messageField =$("textarea#message").val();

    var html = $.ajax({
    type: "POST",
    url: "ajax.recaptcha.php",
    data: "recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField +"&name="+ nameField +"&email=" + emailField +"&phone="+ phoneField + "&reason=" + reasonField +"&message=" + messageField,
    async: false
    }).responseText;

    if(html == "success")
    {
        $('#contactForm').each (function(){
          this.reset();
         Recaptcha.reload();
        }) 

        $("#thanks").html("Thank you");


         return false;
    }

    else
    {
        $("#captchaStatus").html("Your captcha is incorrect. Please try again");
        Recaptcha.reload();
        return false;
    }
}

Upvotes: 0

Views: 1872

Answers (2)

OverZealous
OverZealous

Reputation: 39570

Why don't you simply add this:

$("#captchaStatus").html("");

right below:

$("#thanks").html("Thank you");

That should clear out your error message.

Upvotes: 0

ShankarSangoli
ShankarSangoli

Reputation: 69905

Use a reset button to clear the form feilds.

<input type="reset" />

Upvotes: 7

Related Questions