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
Anirudh Sharma 5Anirudh Sharma 5 

I have a VF page

I have a VF page and I have a multi check box field in that so when a person selects certain options in that question dynamicaly another field should populate when he selects certain options. so how can I do that.

Thanks 
lakslaks
Hi Anirudh,

The following VF page has 4 checkboxes and a textbox. The textbox is populated with the value of the checkbox that is selected.

You can use the code and modify it as per your requirement.

VF Page :
<apex:page controller="ChkboxController">
    <apex:form >
      <apex:selectCheckboxes value="{!certVals}">
          <apex:selectOptions value="{!items}"></apex:selectOptions>
          <apex:actionSupport reRender="valcert" event="onchange" action="{!printValue}"/>          
      </apex:selectCheckboxes> 
      
     <apex:outputPanel id="valcert">
         <apex:inputText value="{!certValue }"></apex:inputText>          
     </apex:outputPanel>
      
    </apex:form> 
</apex:page>
Controller :
public with sharing class ChkboxController
{

    public String certValue { get; set; }
    
    String[] certVals = new String[]{};
    
    public ChkboxController()
    {
    }
    
    public List<SelectOption> getItems() 
    {        
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('Salesforce Admin','Salesforce Admin'));
        options.add(new SelectOption('Salesforce Advance Admin','Salesforce Advance Admin'));
        options.add(new SelectOption('Salesforce Developer','Salesforce Developer'));
        options.add(new SelectOption('Other','Other'));
        return options;
    }
    
    public String[] getcertVals() 
    {
        return certVals; 
    }
    
    public void setcertVals(String[] certVals)
    {
        this.certVals = certVals;
    }
    
    public pageReference printValue()
    {
        if(!certVals.isEmpty())
        {
            certValue = certVals[0];           
        }
        else
        {
            certValue = '';
        }
        return null;
    }    
}
Use it only as a template and do all the necessary checks and modification as per your requirement.

Regards,
Lakshmi.

PS: If this resolved your issue kindly mark it as the solution.