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
Rajat Mahajan 21Rajat Mahajan 21 

Need to go to top of page after an error is thrown in Visualforce page

Hi All

One of our VF pages length is long and the messages get shown at the top of the page.
However, when messages are shown , the user needs to navigate to top to check error.

Are there any workarounds to send the user to the top of the page on any click ?

Many thanks in advance,
Vivek DeshmaneVivek Deshmane
Hi Rajat,
Could you please try below code and change it according to your need and let me know if it works.
<apex:pageMessage id="msgId"/>
<apex:commandbutton value="save" and oncomplete="setFocus()"/>
function setFocus(){
var msgComp=document.getElementById(
	if(msgComp.innerText!=null && msgComp.innerText!='undefined'&&msgComp.innerText.length>0)

Best Regards,