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
astroboiiiastroboiii 

Visualforce taborder - How to set focus on the first field if it is a picklist field?

I have noticed that in a VF page if you have a picklist field as your first field the initial field set to focus is the first non-picklist field.  This is undesireable and odd as I want the user's tab-focus to be on the first field of the page.

 

has anyone else noticed this and know a way to achieve the desired (expected) result?  I have already tried setting focus to the field in question via js but it seems to be ignored or some other script included by SFDC is being run to set the tab index to the first non-picklist field.

 

Thanks in advance to all those who view/help.

Best Answer chosen by Admin (Salesforce Developers) 
astroboiiiastroboiii

Solved this by using the accepted standard workaround for similar issues:

 

At the top of the page I overwrote the SetFocusOnLoad JS function and then elsewhere in my code I explicitely set focus to the first field via the Focus() js function.

All Answers

astroboiiiastroboiii

Solved this by using the accepted standard workaround for similar issues:

 

At the top of the page I overwrote the SetFocusOnLoad JS function and then elsewhere in my code I explicitely set focus to the first field via the Focus() js function.

This was selected as the best answer
s.prasath1130@my.coms.prasath1130@my.com

i have noticed a problem like u and now i got the answer .If the showheader is true ,visualforce inbuilt javascript will run while load the page.in that time we cannot use window.onload. hence it automatically focus the first non picklist field by inbuilt javascript.

 

     To overcome those rules we have to write some java scripts like here:

It will work even showheader is true,,,,

 

<script>

         function  setFocusOnLoad(){ call.focus(); }

</script>

 

 write the above code to the header.

and

   <script>

                var call = document.getElementById('{!$Component.fieldId}')

   </script>

write above code where the inputfield is coded, or my example is

Example:::

   

    <apex:page  standardController="user" sidebar="false" showHeader="true"  id="p">

    <script>

               function setFocusOnLoad(){ mass.focus();} 
    </script>   

             <apex:form id="theForm" >
             <apex:pageBlock id="block">

             <apex:pageBlockSection id="sec" >
             <apex:pageBlockSectionItem id="item">
             <apex:outputLabel value="Company Name"> </apex:outputLabel>   
             <apex:inputField value="{!us.Companyname}" id="maas" taborderhint="2" />    
             </apex:pageBlockSectionItem>
             </apex:pageBlockSection>

             </apex:pageBlock>

             </apex:form>            

            <script>  
                        var mass=document.getElementById('{!$Component.theForm.block.sec.item.maas}');

             </script>

 </apex:page>

 

 

 i mentioned only one field here but it will work if many field presence and also focus picklist also,,,,,

thank you,,,,