function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Need to scroll back to error messages in VF page

HI All,

I have created a visualforce page which contains many inputfileds to accept values from user. i'm showing some visualforce error messages on top of the page, if user forgets to enter values in inputfields. 
what i want here is whenever user enters some values and clicked on submit button,if it shows any errors it should automatically go back to the the place where error messages are displyed.(i.e we need to set focus on Error messages.)
I hope my question is clear.
Any suggestions or code snippet is appriciated.


Mahesh DMahesh D
Hi Lakshman,

Please find the below:

You can use the 

<apex:message> tag.
<apex:page controller="TestMessageController">
	<apex:form >
		<apex:outputLabel value="Test String" /><apex:inputText value="{!test.Name}" id="test"/>
		<br/><apex:message for="test"/>
public class TestMessageController{
    public Account test{get;set;}
    public TestMessageController(){


Also look into other options provided here:

Please do let me know if it helps you.

Naval Sharma4Naval Sharma4
Hi Laxman,

In order to achieve this in your page you have to add a javascript code that needs to be rerender on onComplete call of your commandbutton.
<apex:outputPanel id="jsCode">
            var divID = '.' + classOfPageMessage/Div;
            $('html, body').animate({
                scrollTop: $(divID).offset().top
            }, 2000);

put "jsCode" in the rerender property of commandbutton.
Hi Naval Sharma,
Thanks for you reply.
Can you tel me what i have to in place of ClasOfPAgeMessage in the above script.

If you dont mind can you post full code of vf page.
Thanks in advance.
Hi Naval sharma,

Can you please post some code snippet.waiting for your response.
it's urgent buddy..:)