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
StaciStaci 

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 
if(profileName.indexOf("Customer")!=-1)
{
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.")
window.parent.location='/apex/rejectCustomer?Id={!Change__c.Id}&retURL=/{!Change__c.Id}';

 Apex Page:

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


</apex:page>

 Apex Class:

public class rejectChangeCustomer
{
private final Change__c chge;    
public rejectChangeCustomer(ApexPages.StandardController controller) 
{        
this.chge=(Change__c)Controller.getrecord();     
}         
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='+DateTime.now().format().escapeHtml4()+'&saveURL='+Id);  
 retPage.setRedirect(true);
 return retPage;        
 }}

 

sfdcsushilsfdcsushil

Hello,

 

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

 

Regards,

Sushil

amarcuteamarcute

Hi,

 

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">
<script>
  function setFocus() {
   document.getElementById('{!$Component.myForm.text2}').focus();
  }   
</script>

    <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:form>
    <apex:outputPanel id="out">    
    </apex:outputPanel>
<script language="javascript">
    <body onload="setFocus()">
</script>
</apex:page>

 

 

 

StaciStaci

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