Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Image1

Image2

here i have crated a vf page and wrote a script but the labels are not hide please let me know? This was the below code..

<apex:page standardController="opportunity">
<apex:includeScript value="{!$Resource.jquery}"/>

<apex:sectionHeader title="opportunity Edit" subtitle="{!opportunity.name}"/>
<apex:form>
 <apex:pageBlock title="opportunity Edit" mode="edit">
  <apex:pageBlockButtons location="top">
   <apex:commandButton value="Save" action="{!save}"/>
   <apex:commandButton value="Save & New" action="{!save}" />
   <apex:commandButton value="Cancel" action="{!cancel}"/>
  </apex:pageBlockButtons>
  <apex:pageBlockButtons location="bottom">
   <apex:commandButton value="Save" action="{!save}"/>
   <apex:commandButton value="Save & New" action="{!save}" />
   <apex:commandButton value="Cancel" action="{!cancel}"/>
  </apex:pageBlockButtons>

  <apex:pageBlockSection title="Opportunity Information" columns="2">
   <apex:inputField value="{!opportunity.Name}" required="true"/>
   <apex:inputField value="{!opportunity.Type}" required="false"/>
   <apex:inputField value="{!opportunity.CloseDate}"/>
   <apex:inputField value="{!opportunity.StageName}"/>

   <apex:inputField value="{!opportunity.LeadSource}" required="false"/>
   <apex:inputField value="{!opportunity.AccountId}" required="false"/>
   <apex:inputField value="{!opportunity.IsPrivate}" required="false"/>
   <apex:inputField value="{!opportunity.CampaignId}" required="false"/>            
  </apex:pageBlockSection>

  <apex:pageBlockSection title="Contract Information" columns="1">

   <apex:inputField value="{!opportunity.Funding_Type__c}" id="type" onchange="fund(this)"/>                 

   <apex:inputField value="{!opportunity.X60_Minute_Funding_Amt__c}" html-class="dollor"  required="false" id="id1"/>
   <apex:inputText value="{!opportunity.X60_Minute_Funding__c}" html-class="percentage" required="false" id="id5"/>

   <apex:inputText value="{!opportunity.X3_Hour_Funding_Amt__c}" html-class="dollor" required="false" id="id2" />
   <apex:inputField value="{!opportunity.X3_Hour_Funding_1__c}" html-class="percentage" required="false" id="id6"/>

   <apex:inputText value="{!opportunity.Next_Day_Funding__c}" html-class="dollor" required="false" id="id3"/>
   <apex:inputField value="{!opportunity.Next_Day_Funding_Perc__c}" html-class="percentage" required="false" id="id7"/>

   <apex:inputText value="{!opportunity.Same_Day_Funding_Amt__c}" html-class="dollor" required="false" id="id4"/>
   <apex:inputField value="{!opportunity.Same_Day_Funding_1__c}" html-class="percentage" required="false" id="id8"/>
  </apex:pageBlockSection>
 </apex:pageBlock>
</apex:form>

 <script type="text/javascript">

  function fund(s){

    if(s.value =='$'){
      j$ = jQuery.noConflict();
      j$(".dollor").show();
      j$(".percentage").hide();
    }else
    if(s.value =='%'){
      j$ = jQuery.noConflict();
      j$(".dollor").hide();
      j$(".percentage").show();
    }else{
      j$ = jQuery.noConflict();
      j$(".dollor").show();
      j$(".percentage").show();
    }
  }

 </script>
</apex:page>
share|improve this question

1 Answer 1

The input fields are turned into more than one component at render time, the labels and the input elements are separate so you'd need to hide both. A more standard way to do this would be to allow a call back to the server rather than using Javascript, sure it wouldn't be as fast as runtime but it will make the code a lot simpler. You'd just add an actionSupport attribute to the picklist, re-render the section containing the fields and use the rendered attribute on the fields to control display.

If you definitely want to stick with the approach you have then you can take advantage of the fact that each label element has a for attribute, the value for which will be the id of the element it relates to. I've moved the longer show/hide code into a new function just to make fund() easier to read:

function changeDisplay(type, show){
    j$ = jQuery.noConflict();

    if(show){
        j$(type).show();
        j$(type).each(function(){
            j$("label[for='" + this.id + "']").show();
        });
    } else {
     j$(type).hide();
        j$(type).each(function(){
            j$("label[for='" + this.id + "']").hide();
        });
    }
}

function fund(s){

    if(s.value == "$"){
        changeDisplay(".dollar", true);
        changeDisplay(".percentage", false);
    }else
    if(s.value =='%'){
        changeDisplay(".dollar", false);
        changeDisplay(".percentage", true);
    }else{
        changeDisplay(".dollar", true);
        changeDisplay(".percentage", true);
    }
}

You could also use the value of the s parameter more directly (assuming here that "--None--" has the back-end value ""):

function fund(s){
    changeDisplay(".dollar", s.value == "$" || s.value == "");
    changeDisplay(".percentage", s.value == "%" || s.value == "");
}

While we're here, if you have the word dollor on screen anywhere then note that it's actually spelt dollar ;) Finally, you don't need two <apex:pageBlockButtons> sections to get them at the top and the bottom, you can just set location to "both".

share|improve this answer
    
I didnt get it will you please change my code and post it. –  venkatesh Apr 17 at 6:12
    
You should be able to just replace your javascript function with the two I've posted here and it'll work, though you will need to change 'dollor' to 'dollar' in the class names in the html, or 'dollar' to 'dollor' in my code. –  LaceySnr Apr 17 at 6:13
    
Superb thanku its working fine.. –  venkatesh Apr 17 at 6:18
    
Sweet! I see you're new here, so don't forget to mark the answer as accepted - there's a button to 'tick' it. Welcome to SFSE! –  LaceySnr Apr 17 at 6:20
    
Hi LaceySnr , Its working but after saving the record the % values also displaying. –  venkatesh Apr 23 at 6:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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