2

Possible Duplicate:
jQuery/Javascript function to clear all the fields of a form

I need to clear the form after submit but none of the methods I've seen works for me. I'm using a script I bought but the author isn't answering my request. I have JS file with this:

$('#contact_form').submit(function () {
        $.ajax({
            type: 'POST',
            url: 'contact.php',
            data: {
                name: $('#contact_form input#name').val(),
                email: $("#contact_form input#email").val(),
                text: $("#contact_form textarea").val()
            },
            success: function(data) {
                if ( data == 'sent' ) {
                    $('#contact_form .status').html('Thanks');
                } else if ( data == 'invalid' ) {
                    $('#contact_form .status').html('Invalid.');
                } else {
                    $('#contact_form .status').html('Can't send message.');                 
                }
            },
            error: function () {
                $('#contact_form .status').html('Can't send message.');
            }
        });
        return false;
    });


}
Community
  • 1
  • 1
  • 1
    I would answer, but I have before - [jQuery function to clear all the fields of a form](http://stackoverflow.com/questions/6653556/jquery-function-to-clear-all-the-fields-of-a-form) – Jason McCreary Jul 26 '12 at 20:10
  • It might have something to do with your unescaped apostrophes. `'Can't send message.'` should be `'Can\'t send message.'` or `"Can't send message."` – Jason Swett Jul 26 '12 at 20:11
  • 1
    Rather than that, I'm wondering if you even have the right to modify the script at all. I mean, if you bought a script, then shouldn't the creator retain all modification rights? You might wanna check that before you do anything... rash. – Palladium Jul 26 '12 at 20:11

2 Answers2

8

You mean aside from the basic document.getElementById("contact_form").reset()?

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
0
$('#contact_form').submit(function () {
    $.ajax({
        type: 'POST',
        url: 'contact.php',
        data: $('#contact_form').serialize(),
        success: function(data) {
            if ( data == 'sent' ) {
                $('#contact_form .status').html('Thanks');
            } else if ( data == 'invalid' ) {
                $('#contact_form .status').html('Invalid.');
            } else {
                $('#contact_form .status').html("Can't send message.");
            }
            $('#contact_form').trigger("reset");
        },
        error: function () {
            $('#contact_form .status').html("Can't send message!");
        }
    });
    return false;
});
Snow Blind
  • 1,164
  • 7
  • 12