Below is the code extract from visualforce guide
<apex:page standardController="Account">
<apex:form >
<apex:pageBlock title="Edit Account: {!Account.Name}">
<apex:pageBlockSection title="Account Details" columns="1">
<apex:inputField value="{!Account.Name}" taborderhint="4"/>
<apex:inputField value="{!Account.Website}" taborderhint="3"/>
<apex:inputField value="{!Account.Industry}" taborderhint="2"/>
<apex:inputField value="{!Account.AnnualRevenue}" taborderhint="1"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
In here,taborderhint is in reverse order.My issue is when i land on page ,automatically the very first field is being selected(which has the taborderhint = 4)..Now if i click TAB controls goes to the global search (with skip to main content link highlighted)
Is this the expected behaviour?If so is there any way to focus on a particular input field,as opposed to very first being focused all the time
Attribution to: sfdc99999
Possible Suggestion/Solution #1
You can use javascript to set the focus to a particular field. Add this script text to the end of your page (after the field, and before you close the page
<script type="text/javascript">
document.getElementById('{!$Component.yourComponentId}').focus();
</script>
Something like this:
<apex:page standardController="Account">
<apex:form >
<apex:pageBlock title="Edit Account: {!Account.Name}">
<apex:pageBlockSection title="Account Details" columns="1">
<apex:inputField value="{!Account.Name}" taborderhint="4"/>
<apex:inputField value="{!Account.Website}" taborderhint="3"/>
<apex:inputField value="{!Account.Industry}" taborderhint="2"/>
<apex:inputField id="aRev" value="{!Account.AnnualRevenue}" taborderhint="1"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
<script type="text/javascript">
document.getElementById('{!$Component.aRev}').focus();
</script>
Attribution to: JimRae
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/34164