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>
Attribution to: venkatesh
Possible Suggestion/Solution #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"
.
Attribution to: Matt Lacey
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/32971