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
ChinnoduChinnodu 

Text filed is required Based on select value from pick list

HI Dudes,
I want required on text box ased on picklist value. i having text field is :"Office_Phone__c" and picklist value "Department__c".When evar i can set as Department__c==Department__c"" for that time i want rerquird "Office_Phone__c" filed.
Pls help mr for below code.
<apex:page controller="employmenthistiry" sidebar="true">
    <apex:form >
        <apex:pageBlock id="pgBlckId">
            <apex:pageBlockSection title="Employe" collapsible="false">
                    
                    <apex:inputField value="{! emp.Report__c}"/>
                    <apex:inputField value="{! emp.Name }"/>
                    <apex:inputField value="{! emp.Date_of_joining__c}"/>
                    <apex:inputField value="{! emp.Department__c}"/>
                    
                    <apex:inputField value="{! emp.Desigination__c}"/>
                    <apex:inputField value="{! emp.Email__c}" required="true"/>
                    <apex:inputField value="{! emp.Employeeid__c}"/>
                    <apex:inputField value="{! emp.Mobile__c }"/>
                    <apex:inputField value="{! emp.Office_Phone__c}" required="!IF(emp.Department__c=='IT',true,false)}" id="Office_phonerequired"/>
                    <apex:inputField value="{! emp.payslip_lase_sent_date__c}"/>
                    <apex:inputField value="{! emp.Technology__c}"/>
                  </apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
Regards,
sai
 
atul patil 7atul patil 7
Hello sai,
You can do this by calling one javascript function onchange of department field. in that function you can set it is required or not.
Here is the code:
 
<apex:page controller="employmenthistiry" sidebar="true">
<script>
 j$ = jQuery.noConflict();
function setRequiredFun(arg){
	if(arg=='IT'){
		 j$('[id$=Office_phonerequired]').attr( 'required','true');
	}else{
		j$('[id$=Office_phonerequired]').removeAttr('required');
	}
}
</script>
    <apex:form >
        <apex:pageBlock id="pgBlckId">
            <apex:pageBlockSection title="Employe" collapsible="false">
                    
                    <apex:inputField value="{! emp.Report__c}"/>
                    <apex:inputField value="{! emp.Name }"/>
                    <apex:inputField value="{! emp.Date_of_joining__c}"/>
                    <apex:inputField value="{! emp.Department__c}" onchange="arg='{!emp.Department__c}';setRequiredFun(arg);"/>
                    
                    <apex:inputField value="{! emp.Desigination__c}"/>
                    <apex:inputField value="{! emp.Email__c}" required="true"/>
                    <apex:inputField value="{! emp.Employeeid__c}"/>
                    <apex:inputField value="{! emp.Mobile__c }"/>
                    <apex:inputField value="{! emp.Office_Phone__c}" id="Office_phonerequired"/>
                    <apex:inputField value="{! emp.payslip_lase_sent_date__c}"/>
                    <apex:inputField value="{! emp.Technology__c}"/>
                  </apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>


please Like this answer if you find it helpfull
thanx,
Atul Patil
www.zen4orce.com