+ Start a Discussion
Chiel de Graaf.Chiel de Graaf. 

Change label value after field change

I'm struggeling a little bit with the following.

I've got a visualforce page where i need to change the value of the output label when another field is changed.

Got this code in my VF page

 <apex:pageBlock mode="maindetail" id="thePageBlock"> 
                        <apex:outputPanel layout="block" id="pbsNL" >
                            <apex:pageBlockSection columns="1" title="Kies taal" id="pbsectNL">
                                <apex:pageBlockSectionItem id="pbsitemNL">
                                    <apex:outputLabel value="Taal"/>
                                    <apex:selectList size="1" id="nlSelectList" multiselect="false" onChange="changeLanguage(this.value);"> 
                                        <apex:selectOption itemValue="nl" itemLabel="Nederlands"/>
                                        <apex:selectOption itemValue="en" itemLabel="English" title="Choose language"/>
                                    </apex:selectList>
                                </apex:pageBlockSectionItem>
                            </apex:pageBlockSection>
                        </apex:outputPanel>


The bold values have to change on choosing "en" or "nl".

Anyone any suggestions?


Regards
Chiel
Helen Y.Helen Y.
Hi Chiel,

To achieve the label change, two changes needed in your work:
1. Add actionSupport tage to rerender the outputText tag when selectoption changes;
2. Use custom controller to render the value changes in the outputText based on choosing "en" or "nl". 

Here is the code:
-- VF page:
<apex:page controller="developertest">
 <apex:form >
   <apex:pageBlock mode="maindetail" id="thePageBlock"> 
      <apex:outputPanel layout="block" id="pbsNL" >
         <apex:pageBlockSection columns="1" title="Kies taal" id="pbsectNL" >
            <apex:pageBlockSectionItem id="pbsitemNL">
               <apex:outputText value="{!Taa2}" id="label2"/>
               <apex:selectList size="1" id="nlSelectList" multiselect="false" value="{!n1id}"> 
               <apex:selectOption itemValue="None" itemLabel="None"/>
               <apex:selectOption itemValue="nl" itemLabel="Nederlands"/>
               <apex:selectOption itemValue="en" itemLabel="English" title="Choose language"/>
               <apex:actionSupport event="onchange" rerender="label2" action="{!find}"/>
               </apex:selectList>
             </apex:pageBlockSectionItem>
         </apex:pageBlockSection>
       </apex:outputPanel>
    </apex:pageBlock>
  </apex:form>
</apex:page>

-- Controller:
public class developertest {
  public string Taa2{get; set;}
  public string n1id{get; set;}
  
  public void find(){
    if(n1id == 'nl'){Taa2 = 'Taa2';}
    else if(n1id =='en'){Taa2 = 'Taa1';}
   }
}

You may need some changes to make a better fit, this is the basic concept to make it working.

Helen
Chiel de Graaf.Chiel de Graaf.
Hi Helen,

This gives me a good idea which way to go.
Thank you for your input.


Regards
Chiel