I'm using a visual force page with an extended controller. When I click on the 'Save Only' button the page reloads to the top. How can I keep the focus on the field that a user was on prior to saving ? I am using the save action on the standard controller, not the extended controller. Below is my javascript and visual force snippet where the command button is calling the functions.
Any ideas as to why the page does not scroll down to the last field where the cursor was ?
<script src="/soap/ajax/30.0/connection.js" type="text/javascript"></script>
<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js" />
<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js" />
<script>
var fileldId;
function oncfoucs(){
debugger;
fileldId = $(document.activeElement);
}
function focusComplete(){
fileldId.focus();
}
</script>
............
<apex:outputPanel style="text-align:center" layout="block">
<apex:commandButton styleClass="myClass" action="{!save}" value="Save Only" />
<apex:commandButton styleClass="myClass" action="{!saveAndReturn}" value="Save and Return to Template" />
<apex:commandButton styleClass="myClass" action="{!ReturnMe}" value="Audit Template Screen" />
<apex:commandButton styleClass="myClass" action="{!save}" value="Save Test" onmouseover="oncfoucs();" oncomplete="focusComplete();" />
</apex:outputPanel>
</apex:pageBlockSection>
............
<apex:outputPanel id="ajaxrequest2">
<!-- OPERATIONS -->
<!-- <apex:pageBlockSection columns="1" id="section2" title="Operations" rendered="{!RatingInformation=true}"> -->
<apex:pageBlockSection columns="1" id="section2" title="Operations" rendered="{!Operations}" >
<apex:actionRegion >
<apex:pageBlockSection columns="1" showHeader="false" >
<apex:inputField value="{!Comm_Auto_Audit_Sample_Policy__c.Type_of_Operations__c}" id="operation" rendered="{!TypeOfOperations}" >
<apex:actionSupport event="onchange" reRender="typeOperation" />
</apex:inputField>
</apex:pageBlockSection>
</apex:actionRegion>
<apex:outputPanel id="typeOperation">
<apex:pageBlockSection columns="1" showHeader="false" rendered="{!TypeOfOperations}" >
<apex:inputField value="{!Comm_Auto_Audit_Sample_Policy__c.Service_Operation__c}" rendered="{!Comm_Auto_Audit_Sample_Policy__c.Type_of_Operations__c='Service' && TypeOfService}" />