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
anvesh@force.comanvesh@force.com 

Setting cursor is not working under script to focus on input field in Visual Force page ?

I want to remove focus from first field and want to set the focus on other field while the pages load. But below script doesnt work to set the cursor point on to  other field. can you please how can resolve in my custom visual force page.

<apex:page standardController="Opportunity"  extensions="OppStandardForcarePage">
<apex:sectionHeader title="Opportunity Edit"  subtitle="New Opportunity"/>

<!--<script type="text/javascript">
  window.onload = setFocus
  function setFocus() {
    document.getElementById("Ac").focus();
  }
</script>-->

<apex:form >

<script>
  function setFocusOnLoad()
  {
   document.getElementById("AcText").focus();    //see the id for account field below
  }
</script>



<apex:pageBlock title="Opportunity Edit" mode="edit">

<apex:actionRegion >
<apex:pageBlockSection title="Opportunity Information" columns="2" collapsible="2">
<apex:inputField value="{!Opp.AccountId}" taborderhint="1" id="AcText"/>
Vishal_GuptaVishal_Gupta
Hi ,

Please try below code :

<apex:page standardController="Opportunity"  extensions="OppStandardForcarePage">
<apex:sectionHeader title="Opportunity Edit"  subtitle="New Opportunity"/>
<apex:form >
<apex:pageBlock title="Opportunity Edit" mode="edit">
<apex:actionRegion >
<apex:pageBlockSection title="Opportunity Information" columns="2" collapsible="2">
<apex:inputField value="{!Opp.AccountId}" taborderhint="1" id="AcText"/>
<script>
     document.getElementById("AcText").focus();    //see the id for account field below
</script>

<!--close other tags also- ->
</apex:form>

Please let me know if it will help you.

Thanks,
Vishal