How to disable textbox in Visualforce page based on picklist values?

Sample code:

Visualforce page:


<apex:page controller="Sample">
<apex:form >
<apex:actionFunction name="changeBoolCall" action="{!changeBool}"/>
    <apex:pageblock id="pg">
        <apex:pageblockSection >
            <apex:pageblockSectionItem >
                Select currency :
            </apex:pageblockSectionItem>
            <apex:pageblockSectionItem >
               <apex:selectList value="{!curency}" size="1" multiselect="false">
                   <apex:selectOption itemLabel="--- None ---" itemValue="none"/>
                   <apex:selectOption itemLabel="Indian Rupee" itemValue="inr"/>
                   <apex:actionSupport event="onchange" action="{!changeBool}" reRender="pg"/>
               </apex:selectList>
            </apex:pageblockSectionItem>           
            <apex:pageblockSectionItem >
                Enter the amount:
            </apex:pageblockSectionItem>     
            <apex:pageblockSectionItem >
               <apex:inputtext value="{!amount}" disabled="{!curencyBool}"/>
            </apex:pageblockSectionItem>                  
        </apex:pageblockSection>
    </apex:pageblock>
</apex:form>   
</apex:page>

Apex Controller:

public class Sample
{
    public String curency {get;set;}
    public String amount {get;set;}
    public Boolean curencyBool {get;set;}
   
    public sample()
    {       
        curency = 'none';
        if(curency == 'none')
        {
         curencyBool = true;
        }   
    }
   
    public void changeBool()
    {       
        if(curency != 'none')
        {
            curencyBool = false;
        }
        else
        {
            curencyBool = true;
        }
    }
      
}

Output:


No comments:

Post a Comment