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
mac adminmac admin 

Clear the values in the custom picklist dependent fields

Hi everyone,
In my custom vf page i have create a picklist with 3 different values,when a value is selected from picklist then related dependent fields are showing. some fields are comman for picklist values. I want to clear the values in those common fields when picklist value is changed.
 Can anyone help me over here.

Regards,
mac.
Best Answer chosen by mac admin
VineetKumarVineetKumar
Since you are not using any custom controller / extension, you may have to go with javascript to clear out the value in the field on change of picklist value.
Something like below :
<apex:inputField value="{!IntakeGraduation__c.<fieldName>}" onchange="clearValue();"/>
<script>
    function clearValue(){
		document.getElementById('{!$Component.page:frm:pblck:pbSectn:pbSitemLookup:accountLookup}').value = '';
		document.getElementById('{!$Component.page:frm:pblck:pbSectn:pbSitemLastName:contactLastname}').value = '';
		alert();
		return false;
    }
</script>

Do remember to create the proper hierarchy of Id's in your VF page to reach your component.
Eg..
<apex:page standardController="IntakeGraduation__c" id="page">
    <apex:form id="frm">
        <apex:pageblock id="pblck">


 

All Answers

YogeshMoreYogeshMore
Hi mac,
When you are changing the picklist value then initialize the object that you have created.
Ex:-  Account Acc = new Account();
 
VineetKumarVineetKumar
Can you refer your code here?
mac adminmac admin
Hi Vineet Thanks for the replay, Below is my code

<apex:page standardController="IntakeGraduation__c">
  <apex:form >
        <apex:pageBlock >
             <apex:pageBlockButtons >
                 <apex:commandButton value="Submit" action="{!save}"/>
                 <apex:commandButton value="Cancel" action="{!cancel}"/>
             </apex:pageBlockButtons>
           <apex:pageBlockSection title="About You" columns="2">
          <apex:inputField value="{!IntakeGraduation__c.name}"/>
           <apex:inputField value="{!IntakeGraduation__c.Middle_Name__c}"/>
           <apex:inputField value="{!IntakeGraduation__c.Last_Name__c}"/>
           <apex:inputField value="{!IntakeGraduation__c.Gender__c}"/>
           <apex:inputField value="{!IntakeGraduation__c.Date_of_Birth__c}"/>
                        </apex:pageBlockSection>
     <apex:pageBlockSection title="Parents Information" columns="1">
            
            <apex:outputLabel value="With whom may we share your information"/>
                             <apex:actionRegion >
                                   <apex:inputField value="{!IntakeGraduation__c.With_whom_may_we_share_your_information__c}">
                                   <apex:actionSupport event="onchange" reRender="ajaxrequest" />
                                   </apex:inputField>
                             </apex:actionRegion>
                        <apex:outputPanel id="ajaxrequest">  
                <apex:pageBlockSection rendered="{!IntakeGraduation__c.Select_program__c =='MFA'}" columns="1">
                          <apex:inputField value="{!IntakeGraduation__c.Select_one_if_mfa__c}"/>
                        
                          <apex:inputField value="{!IntakeGraduation__c.Graduation_Date__c}"/>
                     
                         </apex:outputLabel>
                       <apex:outputLabel value="Are you or have you been enrolled in more than one college for college credit? "/>
                             <apex:actionRegion >
                                   <apex:inputField value="{!IntakeGraduation__c.enrolled_in_more_than_one_college__c}">
                                   <apex:actionSupport event="onchange" reRender="ajaxrequest" />
                                   </apex:inputField>
                             </apex:actionRegion>
                        <apex:outputPanel id="ajaxrequest">  
                <apex:pageBlockSection rendered="{!IntakeGraduation__c.enrolled_in_more_than_one_college__c=='Yes'}" columns="1">
                         <apex:PageBlockSectionItem >
                     <apex:outputLabel value="Number of colleges attended Previously"/>
                             <apex:actionRegion >
                                   <apex:inputField value="{!IntakeGraduation__c.Number_of_colleges_attended__c}" required="true">
                                   <apex:actionSupport event="onchange" reRender="ajaxrequest1" />
                                   </apex:inputField>
                                         </apex:actionRegion>
                                      </apex:PageBlockSectionItem>
                                 <apex:outputPanel id="ajaxrequest1">  
                            <apex:pageBlockSection rendered="{!IntakeGraduation__c.Number_of_colleges_attended__c=='1'}" columns="1">
                                  <apex:inputField value="{!IntakeGraduation__c.Last_College_University_Attended__c}"/>
                                  <apex:inputField value="{!IntakeGraduation__c.College_Information_City_one__c}"/>
                                  <apex:inputField value="{!IntakeGraduation__c.College_Information_State_one__c}"/>
                                  <apex:inputField value="{!IntakeGraduation__c.College_Info_Type_of_enrollment_one__c}"/>
                                  </apex:pageBlockSection>
                                  
                            <apex:pageBlockSection rendered="{!IntakeGraduation__c.Number_of_colleges_attended__c=='2'}" columns="1">
                                   <apex:inputField value="{!IntakeGraduation__c.Last_College_University_Attended__c}"/>
                                  <apex:inputField value="{!IntakeGraduation__c.College_Information_City_one__c}"/>
                                  <apex:inputField value="{!IntakeGraduation__c.College_Information_State_one__c}"/>
                                  <apex:inputField value="{!IntakeGraduation__c.College_Info_Type_of_enrollment_one__c}"/>
                                  
                                  <apex:inputField value="{!IntakeGraduation__c.College_University_Attended_two__c}"/>
                                  <apex:inputField value="{!IntakeGraduation__c.College_Information_City_two__c}"/>
                                  <apex:inputField value="{!IntakeGraduation__c.College_Information_State_two__c}"/>
                                  <apex:inputField value="{!IntakeGraduation__c.College_Info_Type_of_enrollment_two__c}"/>
                               </apex:pageBlockSection>       
                            </apex:outputPanel>
                      </apex:pageBlockSection>
                          </apex:outputPanel>
                    </apex:pageBlockSection>                                     
                 
                  <apex:pageBlockSection rendered="{!IntakeGraduation__c.Enrollment_Classification__c=='Transfer'}" >
                          <apex:inputField value="{!IntakeGraduation__c.Full_name_of_last_college_attended__c}"/>
                          <apex:inputField value="{!IntakeGraduation__c.Graduation_or_Withdrawal_Date__c}"/>
                          <apex:inputField value="{!IntakeGraduation__c.Have_you_previously_applied_to_MCA__c}"/>
                         <apex:outputLabel value="Were you previously enrolled for credit at our school?">
                              <apex:inputField value="{!IntakeGraduation__c.enrolled_for_credit_at_our_school__c}"/>
                         </apex:outputLabel>
                           <apex:PageBlockSectionItem >
                     <apex:outputLabel value="Number of colleges attended Previously"/>
                             <apex:actionRegion >
                                   <apex:inputField value="{!IntakeGraduation__c.TrNumber_of_colleges_attended_Previously__c}" required="true">
                                   <apex:actionSupport event="onchange" reRender="ajaxrequest1" />
                                   </apex:inputField>
                                         </apex:actionRegion>
                                      </apex:PageBlockSectionItem>
                                 <apex:outputPanel id="ajaxrequest1">  
                             <apex:pageBlockSection rendered="{!IntakeGraduation__c.Number_of_colleges_attended__c=='1'}" columns="1">
                                  <apex:inputField value="{!IntakeGraduation__c.Last_College_University_Attended__c}"/>
                                  <apex:inputField value="{!IntakeGraduation__c.College_Information_City_one__c}"/>
                                  <apex:inputField value="{!IntakeGraduation__c.College_Information_State_one__c}"/>
                                  <apex:inputField value="{!IntakeGraduation__c.College_Info_Type_of_enrollment_one__c}"/>
                                  </apex:pageBlockSection>
                                  
                            <apex:pageBlockSection rendered="{!IntakeGraduation__c.Number_of_colleges_attended__c=='2'}" columns="1">
                                   <apex:inputField value="{!IntakeGraduation__c.Last_College_University_Attended__c}"/>
                                  <apex:inputField value="{!IntakeGraduation__c.College_Information_City_one__c}"/>
                                  <apex:inputField value="{!IntakeGraduation__c.College_Information_State_one__c}"/>
                                  <apex:inputField value="{!IntakeGraduation__c.College_Info_Type_of_enrollment_one__c}"/>
                                  
                                  <apex:inputField value="{!IntakeGraduation__c.College_University_Attended_two__c}"/>
                                  <apex:inputField value="{!IntakeGraduation__c.College_Information_City_two__c}"/>
                                  <apex:inputField value="{!IntakeGraduation__c.College_Information_State_two__c}"/>
                                  <apex:inputField value="{!IntakeGraduation__c.College_Info_Type_of_enrollment_two__c}"/>
                               </apex:pageBlockSection>       
                         
                                             
                           </apex:outputPanel>
                    </apex:pageBlockSection>  
                       
                    <apex:pageBlockSection rendered="{!IntakeGraduation__c.Enrollment_Classification__c=='Re-enroll'}" columns="1">
                          <apex:inputField value="{!IntakeGraduation__c.Last_date_enrolled_at_MCA__c}"/>
                            </apex:outputPanel>
                     </apex:pageBlockSection>
        </apex:pageBlock>
  </apex:form>

</apex:page>
 
VineetKumarVineetKumar
Since you are not using any custom controller / extension, you may have to go with javascript to clear out the value in the field on change of picklist value.
Something like below :
<apex:inputField value="{!IntakeGraduation__c.<fieldName>}" onchange="clearValue();"/>
<script>
    function clearValue(){
		document.getElementById('{!$Component.page:frm:pblck:pbSectn:pbSitemLookup:accountLookup}').value = '';
		document.getElementById('{!$Component.page:frm:pblck:pbSectn:pbSitemLastName:contactLastname}').value = '';
		alert();
		return false;
    }
</script>

Do remember to create the proper hierarchy of Id's in your VF page to reach your component.
Eg..
<apex:page standardController="IntakeGraduation__c" id="page">
    <apex:form id="frm">
        <apex:pageblock id="pblck">


 
This was selected as the best answer
mac adminmac admin
Thank You Vineet.
 
VineetKumarVineetKumar
Do mark my answer as best answer if it helped solve your problem