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

set focus on certain field

I have a Reject button that when clicked, an alert message comes up asking the customer to fill in a certain box.  They click ok on the alert and the edit page comes up.  I'd like it to render to the field they are supposed to fill out, which is towards the bottom of the page.  


Here's whats going on in my code.  This is only for the customer users.  They click the Reject button, they get an alert message, they click ok.  The edit screen shows up and they can either add their reject comments and click Save or click Cancel.


Button code where customer logic happens:

//If current users profile is Customer Portal, fill in the current users name for Contact Rejected and fill in the current date and time 
alert("You have selected to reject this change.  Please fill in the Contact Rejected Comments in the Rejected Information section towards the bottom this Change record.")

 Apex Page:

<apex:page standardController="Change__c" extensions="rejectChangeCustomer" action="{!autorun}">


 Apex Class:

public class rejectChangeCustomer
private final Change__c chge;    
public rejectChangeCustomer(ApexPages.StandardController controller) 
public pageReference autorun()
ID Id =  ApexPages.CurrentPage().getParameters().get('Id');              


 PageReference retPage = new PageReference('/' + Id + '/e?retURL='+Id+'&00Na000000BA4IU=1&00Na000000BA4IW='+UserInfo.getName()+'&00Na000000BA4Ip=Rejected&00Na000000BA4IV=''&saveURL='+Id);  
 return retPage;        





You can write simple onload javascript. Using id of that field, you can set the focus.







You can set AutoFocus on the required field with the help of JavaScript on a VF page. Checkout the following example.


<apex:page tabStyle="Account">
  function setFocus() {

    <apex:form id="myForm">

        <apex:outputtext >Name:</apex:outputtext>
        <apex:inputText id="text1"></apex:inputText><br></br><br></br>
        <apex:outputtext >Name2:</apex:outputtext>
        <apex:inputText id="text2"></apex:inputText><br></br><br></br>
        <apex:outputtext >Name3:</apex:outputtext>
        <apex:inputText id="text3"></apex:inputText><br></br><br></br>                
        <apex:commandButton id="click" value="Click Me"></apex:commandButton>
    <apex:outputPanel id="out">    
<script language="javascript">
    <body onload="setFocus()">





amarcute, that's not working.  Its almost like it never gets to that part of the code when it executes.  Any other ideas?