+ Start a Discussion
DannyK89DannyK89 

Return to top

I have created a command button that rerenders some Other fields Using the ReRender attribute. However I need the page to return to the top after the button is pressed. I have tried removing the rerender attribute but this leads the page to do something like a refresh and some values on the page change. I would like to know if there was a way to force the page to go to the top while keeping the rerender attribute. Thanks.

 

Here is the command button:

 

<apex:commandButton value="Save" action="{!SaveCand}" reRender="Error, Error2"/>

Best Answer chosen by Admin (Salesforce Developers) 
joshbirkjoshbirk

First option which comes to mind would be to put an anchor at the top of the page, name it something like top:

<a name="top"></a>

 Then use the oncomplete attribute of commandbutton:

oncomplete="window.location.href='#top'"

 Or most browsers these days allow to control scrolling via JavaScript, a la "window.scrollTo" - but I think different browsers have different implementations there.