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
arosysarosys 

picklist

hi 

I am a newbie .

Please help me how to create a VF page based on following

1 . There is piclklist containg 2 values credit/debit

2. And based on the value selected a textbox will be created ether debit or credit .

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
Karthikeyan JayabalKarthikeyan Jayabal

Try the below sample code:

 

PAGE:

<apex:page controller="controller_picklistDemo">
<apex:form >
    <apex:pageBlock mode="edit">
        <apex:pageBlockButtons location="top">
            <apex:selectList multiselect="false" size="1" value="{!selectedValue}">
                <apex:selectOptions value="{!options}"/>
                <apex:actionSupport event="onchange" reRender="pbSection" status="pStatus"/>
            </apex:selectList>
            <apex:actionStatus id="pStatus" startText="Rendering..."/>
        </apex:pageBlockButtons>
        <apex:pageBlockSection id="pbSection" columns="1">
            <apex:pageBlockSectionItem rendered="{!selectedValue='Credit'}">
                <apex:outputLabel value="Credit:"/>
                <apex:inputText />
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem rendered="{!selectedValue='Debit'}">
                <apex:outputLabel value="Debit:"/>
                <apex:inputText />
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>
</apex:page>

 

CONTROLLER:

public class controller_picklistDemo {
    //Picklist selected Value
    public String selectedValue { get; set; }
    
    //Picklist values
    public List<SelectOption> getOptions() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('Credit','Credit'));
        options.add(new SelectOption('Debit','Debit'));
        return options;
    }
    
    //Constructor to initialize picklist value
    public controller_picklistDemo() {
        selectedValue = 'Credit';
    }
}

 

All Answers

s-Forces-Force

Hi Arosys,

 

You need to create a vf page which display one picklist and render text box field on basis of picklist value selected.

 

You can Check the below link this will help you :

 

http://boards.developerforce.com/t5/Visualforce-Development/Render-based-on-the-picklist-Value-selection/td-p/253055

 

Thanks

 

arosysarosys

Thanks for the reply , but i am not clear as i am new in VF coding ,can you elaborate it a little bit?

Karthikeyan JayabalKarthikeyan Jayabal

Try the below sample code:

 

PAGE:

<apex:page controller="controller_picklistDemo">
<apex:form >
    <apex:pageBlock mode="edit">
        <apex:pageBlockButtons location="top">
            <apex:selectList multiselect="false" size="1" value="{!selectedValue}">
                <apex:selectOptions value="{!options}"/>
                <apex:actionSupport event="onchange" reRender="pbSection" status="pStatus"/>
            </apex:selectList>
            <apex:actionStatus id="pStatus" startText="Rendering..."/>
        </apex:pageBlockButtons>
        <apex:pageBlockSection id="pbSection" columns="1">
            <apex:pageBlockSectionItem rendered="{!selectedValue='Credit'}">
                <apex:outputLabel value="Credit:"/>
                <apex:inputText />
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem rendered="{!selectedValue='Debit'}">
                <apex:outputLabel value="Debit:"/>
                <apex:inputText />
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>
</apex:page>

 

CONTROLLER:

public class controller_picklistDemo {
    //Picklist selected Value
    public String selectedValue { get; set; }
    
    //Picklist values
    public List<SelectOption> getOptions() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('Credit','Credit'));
        options.add(new SelectOption('Debit','Debit'));
        return options;
    }
    
    //Constructor to initialize picklist value
    public controller_picklistDemo() {
        selectedValue = 'Credit';
    }
}

 

This was selected as the best answer
arosysarosys

Thanks for your reply , Is there any complete documentation of Visualforce development regarding each & every tag of it.