jQuery closing pop-up after successful form submit

Posted by RyanP13 on Stack Overflow See other posts from Stack Overflow or by RyanP13
Published on 2010-03-08T16:25:07Z Indexed on 2010/03/11 5:33 UTC
Read the original article Hit count: 512

Filed under:
|

Hi,

I have a pop up form that i wish to close on successfull submit of the form. Currently we are only validating on the server side which will create an unordered list of validation errors with the class .error_message.

Once the form has been successfully submitted i want to close the window.

Currently the jQuery i am using for this is as follows but does not work because the first time the form has been submitted the number of error messages will always be zero.

$(document).ready(function() {

$('form#emailQuote').submit(function() {

    var $emailErrors = $('form#emailQuote ul.error_message').length;

    alert($emailErrors);

    if ($emailErrors == 0) {
        //window.close();
        alert('no errors');

    } else {
        //alert('errors');
        alert('errors');
    }      
});

});

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript