+ Start a Discussion
Adrian PetitAdrian Petit 

Don't want to go to the top of the page when refresh

Hello,
I'm modifying the Lead page to include more information, and it's become large. I have to scroll up and down to view all the Lead information.
I have some checkbox and list that refresh my page to show more or less inputs/outputs, and every time I select a new item on the list, or check the checkbox, the page refresh and send me to the top. This is really annoying because I have to scroll down to complete the Lead information every time I change an option from my list. Can someone please help me?
This is part of my VF code:

     <apex:pageBlockSection title="Commercial Information">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Country (Commercial)" />
                    <apex:outputPanel >
                        <apex:inputField value="{!lead.Country_Commercial__c}" >
                            <apex:actionSupport event="onchange"
                                    rerender="LeadForm" status="status" action="{!XXX}" />
                        </apex:inputField>
                        <apex:actionStatus startText="applying value..." id="status" />
                    </apex:outputPanel>
                </apex:pageBlockSectionItem>
                
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Province (Commercial)" />
                    <apex:inputField value="{!lead.Province_Commercial_2__c}" />
                </apex:pageBlockSectionItem>
     </apex:pageBlockSection>

I tried to put an anchor in the apex:pageBlockSection like id="CommercialInformation" and a javascript function (see below) called at apex:actionSupport on a onComplete attribute, but it doesn't work.
       function focusOnElement(id) {
            $(id).goTo(); // need to 'go to' this element
        }

Any thoughts or suggestions would be greatly appreciated. Thanks.

Adrian
Best Answer chosen by Adrian Petit
Rahul Sangwan7341Rahul Sangwan7341
<apex:pageBlockSection title="Commercial Information" id="IdCommercial">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Country (Commercial)" />
                    <apex:outputPanel >
                        <apex:inputField value="{!lead.Country_Commercial__c}" >
                            <apex:actionSupport event="onchange"
                                    rerender="IdCommercial" status="status" action="{!XXX}" />
                        </apex:inputField>
                        <apex:actionStatus startText="applying value..." id="status" />
                    </apex:outputPanel>
                </apex:pageBlockSectionItem>
                
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Province (Commercial)" />
                    <apex:inputField value="{!lead.Province_Commercial_2__c}" />
                </apex:pageBlockSectionItem>
     </apex:pageBlockSection>

Hi you are rerendering whole form, which i am getting from your above code................ rerender the particular pageBlockSection Only.............Please refer to change which i did in above code.

Please select this as best answer if it helps you. And please share whole page code if you are still facing an issue.

All Answers

StephenKennyStephenKenny
Hi Adrian,

Instead of refreshing / rerendering the entire page, why dont you just rerender the sections or fields specifically? This way the user will not be forced to the top of the page.

Please remember to mark this thread as solved with the answer that best helps you.

Regards
Stephen 
Rahul Sangwan7341Rahul Sangwan7341
<apex:pageBlockSection title="Commercial Information" id="IdCommercial">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Country (Commercial)" />
                    <apex:outputPanel >
                        <apex:inputField value="{!lead.Country_Commercial__c}" >
                            <apex:actionSupport event="onchange"
                                    rerender="IdCommercial" status="status" action="{!XXX}" />
                        </apex:inputField>
                        <apex:actionStatus startText="applying value..." id="status" />
                    </apex:outputPanel>
                </apex:pageBlockSectionItem>
                
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Province (Commercial)" />
                    <apex:inputField value="{!lead.Province_Commercial_2__c}" />
                </apex:pageBlockSectionItem>
     </apex:pageBlockSection>

Hi you are rerendering whole form, which i am getting from your above code................ rerender the particular pageBlockSection Only.............Please refer to change which i did in above code.

Please select this as best answer if it helps you. And please share whole page code if you are still facing an issue.
This was selected as the best answer
Adrian PetitAdrian Petit
Hello,
StephenKenny, Rahul, thanks so much. You help me a lot.
If I rerender only the section, I'm not forced to go to the top of the page.

Regards.
Adrian.
Rahul Sangwan7341Rahul Sangwan7341
great to hear that :)