You need to sign in to do that
Don't have an account?
Edwin Herrera
Show/Hide HTML elements using IF/Else
I have developed a custom Visual Force Page that requires me to have two possible paragraph elements. One paragraph is Risks/Issues and the other is Value Measurement. This is dependent on the Percent Complete field of the object. If the Percent Complete is 100, Risks/Issues is hidden else Value Measurement is hidden. Below is what I have so far and both paragraphs are showing instead of one. How can I fix this?
<div id="risks">
<div id="sh">
<p id="VZ">Risks/Issues</p>
<p id="VH">Value Measurement</p>
</div>
<script type="text/javascript">
if(Work_Item__c.Percent_Complete__c==100){
$('#VZ').hide();
}else{
$('#VH').hide();}
</script>
<div id="risks">
<div id="sh">
<p id="VZ">Risks/Issues</p>
<p id="VH">Value Measurement</p>
</div>
<script type="text/javascript">
if(Work_Item__c.Percent_Complete__c==100){
$('#VZ').hide();
}else{
$('#VH').hide();}
</script>
<div id="risks">
<div id="sh">
<p id="VZ" style="display:{!IF(Work_Item__c.Percent_Complete__c != 100, 'block','none')}">Risks/Issues</p>
<p id="VH" style="display:{!IF(Work_Item__c.Percent_Complete__c == 100, 'block','none')}">Value Measurement</p>
</div>
OR
You can use this with script:
<div id="risks">
<div id="sh">
<p id="VZ">Risks/Issues</p>
<p id="VH">Value Measurement</p>
</div>
<script type="text/javascript">
$( document ).ready(function() {
if('{!Work_Item__c.Percent_Complete__c}' ==100){
$('#VZ').hide();
}else{
$('#VH').hide();}
})
</script>
All Answers
<div id="risks">
<div id="sh">
<p id="VZ">Risks/Issues</p>
<p id="VH">Value Measurement</p>
</div>
<script type="text/javascript">
if('{!Work_Item__c.Percent_Complete__c}' ==100){
$('#VZ').hide();
}else{
$('#VH').hide();}
</script>
<div id="risks">
<div id="sh">
<p id="VZ" style="display:{!IF(Work_Item__c.Percent_Complete__c != 100, 'block','none')}">Risks/Issues</p>
<p id="VH" style="display:{!IF(Work_Item__c.Percent_Complete__c == 100, 'block','none')}">Value Measurement</p>
</div>
OR
You can use this with script:
<div id="risks">
<div id="sh">
<p id="VZ">Risks/Issues</p>
<p id="VH">Value Measurement</p>
</div>
<script type="text/javascript">
$( document ).ready(function() {
if('{!Work_Item__c.Percent_Complete__c}' ==100){
$('#VZ').hide();
}else{
$('#VH').hide();}
})
</script>
Also you are using jQuery library for this, which would make the code slower.
Better use the formula expression provided by Nayana, if the object is in the context of the page.
<apex:variable var="wi" value="wi" rendered="{!IF(Work_Item__c.Percent_Complete__c==100, true, false)}"><p id="VZ">Value Measurement</p> </apex:variable>
<apex:variable var="wi" value="wi" rendered="{!IF(Work_Item__c.Percent_Complete__c==100, false, true)}"><p id="VH">Risks/Issues</p> </apex:variable>