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
Shravya Rama 9Shravya Rama 9 

Focus on an inputfield after refresh by action support

Hello,
In the following VF page, I use action support to refresh a page. But everytime the page refreshes, focus goes to top of the page. I want to set the focus to one of the field Automatik__c with ID = "FocusID" using script whenever the page refreshes. But its not working.
<script type="text/javascript">
    function addLoadEvent(func) { 
        var oldonload = window.onload;
        if (typeof window.onload != 'function') {
            window.onload = func;
        } else {
            window.onload = function() {
                oldonload();
                func();
            }
        }
    }
    
    function setFocus() {
        document.getElementById('{!$Component.FocusID}').focus();
    }
    addLoadEvent(setFocus);
</script>
             <apex:pageBlockSection >
                  <apex:inputField value="{!res.Automatik__c}"   >
                         <apex:actionSupport event="onchange" action="{!getRefresh}" id = "FocusID" >
            
                    </apex:actionSupport>
                 </apex:inputField>
                    <apex:inputField value="{!res.Navigation__c}" id="ButtonId" >
                   <apex:actionSupport event="onchange" action="{!getRefresh}" >
            
                    </apex:actionSupport>
                 </apex:inputField>
                
            </apex:pageBlockSection>
Can somebody suggest whats wrong with my code or anyother work around. Thank you.