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
zmzigazmziga 

Hide or unhide inputfield based on picklist value

When I create a new user, I have option to select type of user (it can be either x or y-Picklist). And now if I select type x, inputfield called "something" will show (by default it is hidden). And if I select type y, this inputfield will hide. I hoped it would work like this, but it does not.

 

I have the following code:

 <apex:form >
          <apex:pageBlock title="Create new user" tabstyle="User__c">
               <apex:pageBlockSection columns="1">
                  <apex:inputField label="Name" value="{!User__c.name__c}"/>
                  <apex:inputField label="Type of user" value="{!User__c.type__c}">
                      <apex:actionSupport event="onchange" rerender="something"/>
                  </apex:inputField>
                  <apex:pageBlockSection id="something" rendered="{!IF(User__c.type__c='x',true,false)}">
                      <apex:inputField label="Something: " value="{!User__c.something__c}"/>
                  </apex:pageBlockSection>
               </apex:pageBlockSection>
             <apex:pageBlockButtons >
                 <apex:commandButton value="Save" action="{!save}"/>
             </apex:pageBlockButtons>
          </apex:pageBlock>
      </apex:form>

 

Can anybody help me?

Taiki YoshikawaTaiki Yoshikawa

Hi.

 

Try This. actionFunction.

 

<apex:page standardController="Account">
    <apex:form id="form">
        <apex:actionFunction name="refresh" reRender="blockSection" />
        <apex:pageBlock id="block">
            <apex:pageBlockSection id="blockSection">
                <apex:inputField value="{!Account.Name}" onchange="return changeField();" />
                <apex:outputText value="OK" rendered="{!IF(Account.Name != NULL, true, false)}" id="output" />
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
    <script>
        function changeField() {
            refresh();
            return false;
        }
    </script>
</apex:page>

 

Regards,