2

I am trying to hide one DIV if the selected value is not 50 . On salesforce view page I have added Visual Force Page through standard layout option. I want to display that page only if selected vale of Months is not 50 . Below is the code with which I am trying to achieve this. Please note Months is the custom field on Opportunity.

Visual Force Page

<apex:page standardController="Opportunity">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js" type="text/javascript"></script> 

<script type="text/javascript">  

 $j = jQuery.noConflict(true); 
 $j(document).ready 
(    
    function()
    {
       if(Opportunity.months__c != "(50) Fifty" && Opportunity.months__c !="" && Opportunity.months__c != null)
           {
                 $('#note').fadeIn('slow');; 
               sfdcpage.
           }
        else
            {
                $('#note').fadeOut('slow');; 
            }
    }
    )    

<div id="note" class="note">
    <div class="noteTitle">Note</div>
    <div id="noteBody" class="noteBody">
        Some Sample Text Here
    </div>
</div>
        </script>

7
  • Is there a reason you can't do this with standard rendered attributes of outputPanel or pageBlock ?
    – AslamK
    Oct 2, 2015 at 14:46
  • @Ricky I could not get the requirement, you are hiding the div (note) in the if block and again un-hiding it in the else block.
    – Saroj Bera
    Oct 2, 2015 at 15:05
  • @SarojBera it is because I only want to hide is if the value is not 50 if it is 50 I want that to be displayed.
    – Ricky
    Oct 2, 2015 at 15:17
  • @AslamK I tried doing through rendered first but was not working for me. So I have used java script. Is this Achievable through rendered?
    – Ricky
    Oct 2, 2015 at 15:36
  • Yes it should be possible to achieve this using standard tags
    – AslamK
    Oct 2, 2015 at 15:48

1 Answer 1

2

You can simply achieve this through standard tags. I don't see any reason to go for JavaScript for this.

<apex:page standardController="Opportunity">

<apex:outputPanel rendered="{!Opportunity.months__c == '(50) Fifty'}">
    <apex:outputLabel>Some Sample Text Here</apex:outputLabel>
</apex:outputPanel>

</apex:page>
2
  • Oh I was actually using rendered on DIV I needed to use Output Panel . Thanks for you work, That did solve my problem.
    – Ricky
    Oct 2, 2015 at 17:02
  • Can we use the above code to render div?
    – Dev Shaik
    Mar 5, 2017 at 12:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .