views:

18

answers:

1

Hi All

I'm trying to get the height of the error container when using 'jquery validate' plugin when submitting an erronous form, but I can't seem to get the height value of the error container when it appears. The alert box isn't even showing. What is the solution, please?

Here's the code:

$(".validate").validate({
    rules: {
        j_username: "required"
    },
    submitHandler: function(form) {
        //$(":submit", form).attr("disabled","disabled").val("Please wait....");

        $(":submit", form).attr({
                                disabled: "disabled",
                                value: "Please wait...."
                                });         


        var errH = $("#errorMsgContainer").height();
        if($("#errorMsgContainer").is(":visible")){     
            alert("visible and '#errorMsgContainer' height is: " + errH);
        }
        else{
            alert("Not visible and '#errorMsgContainer' height is: " + errH);
        }

        form.submit();

        return false;
    },
    messages: {
        j_username: "Please type your email address correctly!",
        j_password: "Your password and username do not match!"
    },
    ignore: ".catalogueDD",
    errorLabelContainer: $("#errorMsgContainer")
});

Thanks.

A: 

if the element doesn't take up any space in the document, then is(':hidden') will return true even if it is effectively visible, It may be safer to instead do this:

if( !$('#errorMsgContainer').is(':visible') ) {
    // it's hidden, do something
}
else {
    // it's not hidden so do something else
}

SOURCE :: http://www.electrictoolbox.com/jquery-element-is-visible/

From.ME.to.YOU
@From.ME.to.YOU: Thanks for the reply! I just tried your solution but nothing happens when I click the submit button. I'm not sure but I think it's somthing to do with when 'events' are taking place in the 'validate' plugin. All I want is to retrieve the height of the error container when it appears. Since the DOM is loaded I don't see why there should be any problem but it's getting annoying...
Shaoz
1) your #errorMsgContainer is div or what? 2) are you running this code after DOM is loaded ?
From.ME.to.YOU
Yes, it is a div and the code is in '$(document).ready(function(){})'.
Shaoz
try to add css height to that div
From.ME.to.YOU
I added 10px in css. When I click the button, the container shows as 10px height but the alert box is not showing at all. It's like it doesn't even read the code.
Shaoz
try $("#errorMsgContainer").css('height');
From.ME.to.YOU
Nope! I just tried that and it's still doesn't pick the code up. Do you think maybe I shouldn't put the code in the 'submitHandler' option for it to be read? The thing is, I don't know where else I can put the code... if that was the case of course.
Shaoz