function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RustyboyRustyboy 

Simple javascript problem

Apologies, but this is probably a really simple javascript / VF issue, but I have been going around in circles

 

I want to conditionally render a column in a pageBlockTable based on the value of another column in the table. I have written a javascipt function which should return true / false according to the value of the field. 

 

My Javascript function is:

 

<script type="text/javascript">
   function renderStatus(attendeeRole) {

       	if (attendeeRole == "Minutes Only")	{
            return false;
	}
	else {
	    return true;
	} 
   }
</script>

 

The excerpt from the table is:

 

<apex:column headerValue="Invite Status" styleClass="{!att.Status__c}" >
   <apex:inputField value="{!att.Invite_Status__c}" 
       rendered="return(renderStatus('{!att.Role__c}'))" />  
</apex:column>

 

I have tried many different variations of trying to fire the js function but just cannot seem to make it work.

 

The result is always a column that does not render regardless of the value of the field att.Roler__c

 

Thanks in advance

 

PS: I always struggle with javascript in VF. Is there a decent reference document / book out there that can help? 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox
"rendered" is a visualforce attribute, not an HTML/CSS/JavaScript attribute. As such, you can't trigger JavaScript in the rendered attribute. Instead, use the expression directly in the rendered attribute: rendered="{!att.Role__c='Minutes Only'}". This is a Visualforce expression that will conditionally render the element.

All Answers

sfdcfoxsfdcfox
"rendered" is a visualforce attribute, not an HTML/CSS/JavaScript attribute. As such, you can't trigger JavaScript in the rendered attribute. Instead, use the expression directly in the rendered attribute: rendered="{!att.Role__c='Minutes Only'}". This is a Visualforce expression that will conditionally render the element.
This was selected as the best answer
RustyboyRustyboy

Works perfectly, thanks