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
MrithulaMrithula 

how to bring the text box value to radio button or checkbox

hi, 

 

i have a requirement that , the field X  data type is "text" that holds values.

 

but in my Visual Force page the values in X  that has text datatype  should be displayed in "radio button" or  " check box". based on the picklist value.

 

pls help me to achieve this..

 

Thanks in advance.

Best Answer chosen by Admin (Salesforce Developers) 
gbu.varungbu.varun

Hi you can make a list of checkbox by using List of selectoption type

 

/* Selectoption List for checkbox*/
public List<SelectOption> options {get;set;}
options = new List<SelectOption>();
options.add(new SelectOption('Test','Test'));
options.add(new SelectOption('Test','Test'));
options.add(new SelectOption('Test','Test'));
/* Receive input from Salesforce */
public String[] mtv {get;set;}
mtv = new String[]{};
 

 

/* Visualforce Page */
<apex:selectCheckboxes value="{!mtv}" layout="pageDirection">

<apex:selectOptions value="{!options}"/>
</apex:selectCheckboxes>

 

All Answers

PremanathPremanath

Make sence ...

how it is Display in Radio button/ Check box..

 

Question is wrong..

gbu.varungbu.varun

Hi you can make a list of checkbox by using List of selectoption type

 

/* Selectoption List for checkbox*/
public List<SelectOption> options {get;set;}
options = new List<SelectOption>();
options.add(new SelectOption('Test','Test'));
options.add(new SelectOption('Test','Test'));
options.add(new SelectOption('Test','Test'));
/* Receive input from Salesforce */
public String[] mtv {get;set;}
mtv = new String[]{};
 

 

/* Visualforce Page */
<apex:selectCheckboxes value="{!mtv}" layout="pageDirection">

<apex:selectOptions value="{!options}"/>
</apex:selectCheckboxes>

 

This was selected as the best answer
MrithulaMrithula

thanks,

it's working :) 

 

but how can i get the check box  values without hardcoding..?

gbu.varungbu.varun

you can put values into selectoption list through a loop. For example if you have a list of 10 Account you can do it as:

 

List<Account> acnt= [Select name from Account limit 10];

for(Account a:acnt){
options.add(new SelectOption(a.Name,a.Name));
}

 It will return a selectoption list of 10 items.

options.add(new SelectOption('Test','Test'));
MrithulaMrithula

here is my code:

 

PAGE:

<apex:page controller="textcheckbox">
<apex:form >
<apex:pageblock>

<apex:actionRegion>
<apex:inputField value="{!a.Type__c}" label="Select type">
<apex:actionSupport event="onchange" reRender="check,radio"/>
</apex:inputField>
</apex:actionRegion>

<apex:outputPanel id="check">
<apex:outputPanel rendered="{!a.Type__c='Checkbox'}">
<apex:selectCheckboxes value="{!anslist}">
<apex:selectOptions value="{!items}"/>
</apex:selectCheckboxes>
</apex:outputPanel>
</apex:outputPanel>

<apex:outputPanel id="radio" >

<apex:outputpanel rendered="{!a.Type__c='Radiobutton'}">
<apex:selectRadio value="{!anslist}">
<apex:selectOptions value="{!items}"/>
</apex:selectRadio>
</apex:outputPanel>
</apex:outputPanel>
</apex:pageblock>
</apex:form>
</apex:page>

CLASS:

public class textcheckbox{

public list<answer__c> anslist{get; set;}
public answer__c a{get; set;}

public textcheckbox()
{


anslist= (List<answer__c>)[select opt1__c,opt2__c,opt3__c from answer__c ];
a= new answer__c ();
}

 

public List <SelectOption> getitems()
{
List<SelectOption> options = new List<SelectOption>();

options.add(new SelectOption('anslist','anslist.answer__c' ));

return options;

}

}

gbu.varungbu.varun

Hi,


you can make a picklist for opt1 fields as:

anslist= (List)[select opt1__c,opt2__c,opt3__c from answer__c ];

public List getitems()
{
List options = new List();

for(answer__c a:anslist){

options.add(new SelectOption(a.opt1,a.opt1));

}

return options;

}