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
anu_karthianu_karthi 

Dynamically changing output text value

Hi everyone,

 

MY requirement is up on button action i want to change my apex output text value if he click edit button i want to display output text as "Edit mode' .If i click new button i want to display d output as 'New Mode'....Soi want to change the output text value up on command button i tried by assigning likedis in the clear field function

 document.getElementById('{!$Component.form1.head}').Value='CANCEL MODE';

but its not working So plz help me to achieve this with an example code...

My vpage is as follows

<apex:page standardController="CAF_Bank__c" extensions="variable">
<script>

    function clearflds()
    {

   document.getElementById('{!$Component.form1.head}').Value='CANCEL MODE';
   document.getElementById('{!$Component.form1.name}').value=null;
    document.getElementById('{!$Component.form1.iField}').value=null;
    document.getElementById('{!$Component.form1.bname}').value=null;
    document.getElementById('{!$Component.form1.credit}').value=null;
    }
    </script>
<apex:form id="form1" >
 <table width="100%"> <tr>
      <td width="17%"></td>
      <td align="left" valign="top" height="45"><font style="font-family:Tahoma, Geneva, sans-serif; font-size:16px; line-height:24px; color:#900;"><apex:outputText id="head"  title="Search Mode" value="Search Mode" > </apex:outputText>

   
           </font> </td>
   
      <td></td>
  </tr></table>                                       
<table width="100%">
    <tr>
      <td width="5%"></td>
      <td>
          <table width="100%" align="center">
       

               <tr>
                   <td height="30" width="170px"><apex:outputLabel value="Bank Name">
     </apex:outputLabel></td>
                   <td><apex:inputField id="name" value="{!CAF_Bank__c.Bank_Name__c}">
                    <apex:actionSupport event="onkeyup" action="{!disableEnable}" rerender="buttonSection"/>
                   </apex:inputField>
                   </td>
               </tr>
               <tr>
                   <td height="30"><apex:outputLabel value="Branch Code">
      </apex:outputLabel></td>
                   <td><apex:outputPanel id="branchcoding">
     <apex:inputField id="iField" value="{!CAF_Bank__c.Branch_Code__c}">
      <apex:actionSupport event="onkeyup" action="{!disableEnable}" rerender="buttonSection"/>
      </apex:inputfield>
      </td></tr>
      <script>document.getElementById('{!$Component.iField}').disabled = {!disableInput}; </script>
      </apex:outputPanel> 
              
               <tr>
                   <td height="30"><apex:outputLabel value="Branch Name">
     </apex:outputLabel></td>
                   <td><apex:inputField id="bname" value="{!CAF_Bank__c.Branch_Name__c}">
                    <apex:actionSupport event="onkeyup" action="{!disableEnable}" rerender="buttonSection"/>
                   </apex:inputfield>
                   </td>
                 </tr>
                  </table>
<table align="left"><tr><td align="center">

</td></tr></table>

</td><td width="5%"></td></tr>

</table>
<table width="100%"> <tr>
      <td width="12%"></td>
      <td align="left" valign="top" height="45">
        <apex:outputpanel id="buttonSection">
    <apex:commandButton disabled="{!isNewButtonDisabled}" value="New" onclick="newmode();" action="{!newRecord}" />
      <apex:commandButton disabled="{!isEditButtonDisabled}" value="Edit" action="{!disableCloseDateInput}" onclick=" focussing()"  rerender="branchcoding, buttonSection"/>
              <apex:commandButton disabled="{!isSaveButtonDisabled}" id="button2" action="{!save }" value="Save"   />
      <apex:commandButton value="Cancel"  onclick="clearflds()"  reRender="form1" />

 
  <apex:commandButton action="{!cancel}" value="Exit"/>


  </apex:outputpanel>
      </td>
       </apex:form>
  </tr></table>
 
</apex:page>

 

My controller as follows

 

public class variable {

private static final Boolean DISABLED = false;
private static final Boolean ENABLED = true;
public Boolean disableInput {get; set;}
 boolean isSaveButtonDisabled = false;
  boolean isNewButtonDisabled = false;
  boolean isEditButtonDisabled = false;
List<String> BankBranchList = new List<String>();
ApexPages.StandardController con;
public  variable(ApexPages.StandardController controller){ 
setButtonStatus('save', DISABLED);
setButtonStatus('edit', DISABLED);

setButtonStatus('new',ENABLED);
this.con = controller;
}
Public pageReference move()
{

   PageReference newpage=page.variableheading;
   newPage.setRedirect(true);
   return newpage;
  
   }
 public void save() {

try
{

 con.save();
setButtonStatus('save', DISABLED);
setButtonStatus('edit', ENABLED);
setButtonStatus('new', ENABLED);

}
catch(Exception ex1)
{
}


}

public PageReference newRecord()
{
PageReference pr = System.Page.variableheading; // or 'new PageReference('url');//

pr.setRedirect(true);
return pr;

}
public PageReference hmpgmove()
{
PageReference pr =new PageReference('https://ap1.salesforce.com/home/home.jsp'); // or 'new PageReference('url');//

pr.setRedirect(true);
return pr;


public PageReference create()
{

setButtonStatus('save', DISABLED);
setButtonStatus('edit', DISABLED);
setButtonStatus('new',  DISABLED);
enableCloseDateInput();

return move();

}
public boolean getIsSaveButtonDisabled()
{
  return isSaveButtonDisabled;
}
public boolean getIsEditButtonDisabled()
{
  return isEditButtonDisabled;
}
public boolean getIsNewButtonDisabled()
{
  return isNewButtonDisabled;
}
public boolean getIsDeleteButtonDisabled()
{
  return isDeleteButtonDisabled;
}
  public void disableCloseDateInput()
  {
    setButtonStatus('new', DISABLED);
    disableInput = true;
   
    
 }
   
 
    public void enableCloseDateInput(){
        disableInput = false;
    }
 
public void setButtonStatus(String buttonName, Boolean status) {

status = !status;

if (buttonName == 'save') {

isSaveButtonDisabled = status;

} else if (buttonName == 'new') {

isNewButtonDisabled = status;

} else if (buttonName == 'edit') {

isEditButtonDisabled = status;

}
else if(buttonname=='delete')
{
  isDeleteButtonDisabled = status;
}

}
public void disableEnable() {
setButtonStatus('save', ENABLED);
}
}

 

 

                                                                                                                                          Thanks&Regards,

                                                                                                                                                 Anu....

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
BeeddiskShahBeeddiskShah

Erm... i did not go throught the code above, but one thing I learned working on salesforce, avoid javascript if you have too...

 

 

and u can.

 

try this,

 

<apex:outputtext value="{!mode}" />

 <apex:commandbutton action="{!changemode}"/>

 

 

PageReference changeMode(){

if(mode=='A'){

 mode='B';

} else{

mode='A';

}

}

 

I have not compiled it...but it will work.

All Answers

S_LieS_Lie
You can use actionsupport in the button then rerender the field.
BeeddiskShahBeeddiskShah

Erm... i did not go throught the code above, but one thing I learned working on salesforce, avoid javascript if you have too...

 

 

and u can.

 

try this,

 

<apex:outputtext value="{!mode}" />

 <apex:commandbutton action="{!changemode}"/>

 

 

PageReference changeMode(){

if(mode=='A'){

 mode='B';

} else{

mode='A';

}

}

 

I have not compiled it...but it will work.

This was selected as the best answer