1

When i select stage picklist value as "Closed Lost" in Opportunity, then i want show text fields. By-default these text fields will be hide. I tried so many ways but i didn't get. tried using actionsupport, javascript, jquery. Here i am giving one of my code using jquery. can anyone give solution for this issue. thanks in advance. Here by-default textfields displays, but i don't want it. It must be shown when i select stage picklist as "Closed Lost" only.

<apex:page standardController="Opportunity">
  <apex:sectionHeader title="Opportunity Edit" subtitle="New Opportunity" help="www.salesforce.com"/>
  <apex:form >
    <script type="text/javascript">
        function doChange(thiss)
        {
             if(thiss.value == 'Closed Lost'){
              document.getElementById("j_id0:j_id2:j_id4:j_id9:j_id29").style.display='block';
              document.getElementById("j_id0:j_id2:j_id4:j_id9:j_id30").style.display='block';
              document.getElementById("j_id0:j_id2:j_id4:j_id9:j_id31").style.display='block';
              document.getElementById("j_id0:j_id2:j_id4:j_id9:j_id32").style.display='block';
              }
             else {
              document.getElementById("j_id0:j_id2:j_id4:j_id9:j_id29").style.display='none';
              document.getElementById("j_id0:j_id2:j_id4:j_id9:j_id30").style.display='none';
              document.getElementById("j_id0:j_id2:j_id4:j_id9:j_id31").style.display='none';
              document.getElementById("j_id0:j_id2:j_id4:j_id9:j_id32").style.display='none';
              }
        }
    </script>
        <apex:pageBlock title="Opportunity Edit" mode="Edit">
            <apex:pageBlockButtons >
                 <apex:commandButton value="Save" action="{!save}"/>
                 <apex:commandButton value="save & New" action="{!quicksave}"/>
                 <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="Opportunity information" columns="2">
                    <apex:pageBlockSectionItem >
                        <apex:outputLabel > Opportunity Owner</apex:outputLabel>
                        {!$User.FirstName} {!$User.LastName}
                    </apex:pageBlockSectionItem>
                    <apex:inputField value="{!opportunity.CloseDate}"/>
                    <apex:inputField value="{!opportunity.Name}"/>
                    <apex:inputField value="{!opportunity.StageName}" onchange="doChange(thiss);"/>
                    <apex:inputField value="{!opportunity.AccountId}"/>
                    <apex:inputField value="{!opportunity.Probability}"/>
                    <apex:inputField value="{!opportunity.Type}"/>
                    <apex:inputField value="{!opportunity.Amount}"/>
                    <apex:inputField value="{!opportunity.ForecastCategoryName}"/>
                    <apex:inputField value="{!opportunity.Sales_Office__c}"/>
                    <apex:inputField value="{!opportunity.CampaignId}"/>
                    <apex:inputField value="{!opportunity.UI_Code__c}"/>
                    <apex:inputField value="{!opportunity.CurrencyIsoCode}"/>
                    <apex:inputField value="{!opportunity.Jobsite_Location__c}"/>
                    <apex:inputField value="{!opportunity.LeadSource}"/>
                    <div id="myid" style="display:none">
                        <apex:inputField value="{!opportunity.Reason_for_Loss__c}"/>
                        <apex:inputField value="{!opportunity.Lost_To_whom__c}"/>
                        <apex:inputField value="{!opportunity.Competitor_s_Price__c}"/>
                        <apex:inputField value="{!opportunity.Competitor_s_MT__c}"/>
                    </div>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Additional Information" columns="2">
                <apex:inputField value="{!opportunity.NextStep}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Description Information" columns="2">
                <apex:inputField value="{!opportunity.Description}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
1

There are 2 issues:

1) You have an extra 's' in the parameter that you're passing to the doChange function. Change the line to :

<apex:inputField value="{!opportunity.StageName}" onchange="doChange(this);"/>

2) You are toggling the visibility of the child element of the div(id="myId"), but the div itself remains hidden all the time. If the parent is hidden the child elements will always remain hidden regardless of their visibility setting.

So change the doChange function:

function doChange(thiss){
   if(thiss.value=='Closed Lost'){
      document.getElementById("myId").style.display='block';
   }else{
      document.getElementById("myId").style.display='None';
   }

}
| improve this answer | |
  • Hi, thanks for your reply. i modifid the code as per you said. nothing happen. Text fields in div are also displays even we mention style="display:none". – Vijay Kumar Aug 19 '14 at 5:08
  • is there any other script on the page which is changing the visibility of the div. Try removing all the other content on the page and see if the div is still visible when the style is set to "display:none;"? – Sam Aug 19 '14 at 6:43
  • there is no other scripts in page. style is set to display:none only. still it displays. – Vijay Kumar Aug 19 '14 at 7:10
  • thanks for reply, I got solution with using actionRegion. – Vijay Kumar Aug 19 '14 at 16:41
0

Opportunity Owner {!$User.FirstName} {!$User.LastName}

                <apex:outputPanel id="ajaxrequest">  
                  <apex:pageblockSection rendered="{!Opportunity.StageName=='Closed Lost'}" >
                    <apex:inputField value="{!opportunity.Reason_for_Loss__c}"/>
                    <apex:inputField value="{!opportunity.Lost_To_whom__c}"/>
                    <apex:inputField value="{!opportunity.Competitor_s_Price__c}"/>
                    <apex:inputField value="{!opportunity.Competitor_s_MT__c}"/>
                  </apex:pageblockSection>
                </apex:outputPanel>


        </apex:pageBlockSection>
        <apex:pageBlockSection title="Additional Information" columns="2">
            <apex:inputField value="{!opportunity.NextStep}"/>
        </apex:pageBlockSection>
        <apex:pageBlockSection title="Description Information" columns="2">
            <apex:inputField value="{!opportunity.Description}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>

| improve this answer | |
  • Vijay - you might want to correct the code posting so all lines are included. – cropredy Aug 19 '14 at 23:19
  • Actually i posted full code but it will not shows. Here i am paste the actionRegion block. you can check it.<apex:pageblockSectionItem > <apex:outputLabel value="Stage"/> <apex:actionRegion > <apex:inputField value="{!Opportunity.StageName}"> <apex:actionSupport event="onchange" reRender="ajaxrequest" /> </apex:inputField> </apex:actionRegion> </apex:pageblockSectionItem> – Vijay Kumar Aug 20 '14 at 3:11
  • i fixed your code post to display properly – cropredy Aug 20 '14 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.