How to check that any error message is diplaying in visualforce page

i want to perform an action on onComplete event of commandbutton.I am calling javascript function ,in that function i want to know if there is any error displaying on visualforce page(Validation error).Can i implement this without using any controller.

Answer

I wonder if you can use the css class errorMsg of the error block:

enter image description here

If this class exists on the page – there is an error:

<apex:page>
<script>
function checkIt(){
    if (jQuery('.errorMsg').length > 0){
        // Error exists
        alert('There is an error on the page!');
    }
    else{
        alert('No errors!');
    }
}
</script>

<apex:commandButton reRender="none" oncomplete="checkIt();" value="Click me"/>

</apex:page>

Attribution
Source : Link , Question Author : Pankaj , Answer Author : Sergej Utko

Leave a Comment