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
faceroy123faceroy123 

Rendering a field based on a text field

Hi,

 

I need to render 2 different fields based on the input in a text field.


I can work out how to diplay fields / sections based on a checkbox but is this doable based on text input?

Here's my page code so far (which doesn't work).

I want to render the account id lookup if the account number begins with '700'

 

Any help appreciated.

 

<apex:page standardController="Case">
<apex:form >
<apex:sectionHeader title="Case" subtitle="{!Case.CaseNumber}"/>
<apex:pageBlock title="Case">
<apex:pageMessages />
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!Save}"/>
<apex:commandButton value="Cancel" action="{!Cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="New Section" columns="2"><apex:inputField value="{!Case.Account_Number__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection id="theBlock">
   <apex:inputfield value="{!case.Account_Number__c}">
      <apex:actionSupport event="onchange" rerender="theBlock"/>
   </apex:inputfield>

   <apex:inputText value="{!case.accountid}" disabled="false" rendered="{(String)case.account_number__c).substring(0,3) == '700')}"/>
   <apex:inputText value="{!case.accountid}" disabled="true" rendered="{(String)case.account_number__c).substring(0,3) == '700')}"/>

 

Shiv ShankarShiv Shankar

I think we can do it with the help of jQuery

 

<apex:page standarController="Account" sidebar="false" showHeader="false">
        <!-- add jQuery package -- -->
		<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
		
		<-- now we have two filed with us --->
		<!-- on the basis of below field idustry field will be displayed or hide -->
		
		<apex:inputField id="AccountName" onkeyup="hideDisplay(this)" value="{! Account.Name}" /> -----renders as input field - 
										  
		<!-- below field will be hide or displaed -->
		<apex:inputField id="AccountIndustry" value="{!Account.Industry}"/>
		
		<script>
        function hideDisplay(element){
            var text = element.value;
            if(text.substring(0,3) == '700'){
                $('select[id $= "AccountIndustry"]').css('visibility','hidden'); // since idustry standard field renders as select on html so i have used select for others you can use input
            } else{
                $('select[id $= "AccountIndustry"]').css('visibility','visible');
            }
            
        }    
    </script>