+ Start a Discussion
ArpiArpi 

scrolling the page

hello,

 

I have the below vf page as below. When I click the section label ({!section.Section_Label__c}) it would rerender questiondetail block and the page should scroll with top being the data from reender but when I click if I try to scroll to any componenet in the questiondetail block it didnt work,so I had to do it the way below which just shifts littlle not to the start of the data below button.I think it may be because it takes time for data to come from backend.

Q1)Is there any other way I can scroll to the data below save button.

Q2)Is there a way to have some event fire only when the data is completely loaded into the frontend and than scroll or do something.

 

<script language="JavaScript" type="text/javascript">

function scrollWin() {
window.scrollTo(0, 800);

}

</script>

<apex:form id="templateForm">

<apex:pageBlock >


<apex:pageBlockSection id="sectionBlock" title="{!templateName}" columns="1">
<apex:repeat value="{!sectionsStatusLists}" var="section">
<apex:commandLink reRender="questiondetail" onclick="scrollWin()">
<h3>{!section.Section_Label__c}
</h3>
<apex:param name="sectionId" value="{!sectionid}"/>
</apex:commandLink>
</apex:repeat>
</apex:pageBlockSection>
</apex:pageBlock>

<apex:outputPanel id="questiondetail" >
<apex:pageBlock id="block1">

<script>
function focu(){
var e = document.getElementById('{!$Component.buttons1.button1}');
//var e = document.getElementById('thePage:templateForm:questiondetail:block1:buttons1:button1');
e.focus();
}
</script>
<apex:pageBlockButtons location="bottom" id="buttons1" >
<apex:commandButton value="Save" action="{!Save}"  id="button1"/>
</apex:pageBlockButtons>

<apex:repeat value="{!questionsList}" var="question" >

<apex:pageBlockSection columns="1" rendered="{!question.newquestFormat.Question_Type__c=='Text'}" >

<apex:pageBlockSectionItem >
<apex:outputField value="{!question.Subquestion_Label__c}" />
<apex:inputTextarea style="" rows="6" cols="100" id="textInfo" value="{!question.resObj.Response__c}"></apex:inputTextArea>
</apex:pageBlockSectionItem>
</apex:pageBlockSection><br></br>

<apex:pageBlockSection columns="1" rendered="{!question.Question_Type__c=='RadioPicklist'}" >
<apex:outputPanel rendered="{!NOT(ISNULL(question.HelpText__c))}"><b>Q.{!qnum} {!question.Question_Label__c}</b><span class="helpButton" id="help1_Help"><img src="/s.gif" alt="" class="helpIcon" title="{!question.newquestFormat.HelpText__c}"/></span>
</apex:outputPanel>

<apex:pageBlockSectionItem >
<apex:selectRadio layout="pageDirection" id="qOptionList" value="{!question.resObj.Response__c}">
<apex:selectOptions value="{!question.optionsList}"/>
</apex:selectRadio>
</apex:pageBlockSectionItem>
</apex:pageBlockSection><br></br>
</apex:repeat>
</apex:pageBlock>

</apex:outputPanel>

</apex:form>

 

Best Answer chosen by Admin (Salesforce Developers) 
robdobbyrobdobby

Perhaps the page hasn't finished rendering.  Did you try using oncomplete instead of onclick in your commandLink?