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
Adelchi PelizzoAdelchi Pelizzo 

Render pageblocksection using javascript funtion in Visualforce

I would like to show or hide different <apex:pageblocksection>'s depending if a checkbox is selected or not.
I am thinking to use <apex:actionSupport> to add a listener functionality to the <apex:inputfield>  checkbox.
So when the box gets ticked the "onchange" attribute will trigger a java script:
<script type="text/javascript">;
    function ShowSection() {
         document.getElementById("pageid:formid:pageblockId").style.display ='block';
    }
</script>
I have got stuck here, can anybody point me in the right direction please?
Thanks
Best Answer chosen by Adelchi Pelizzo
Adelchi PelizzoAdelchi Pelizzo
Thanks Neetu,

It worked, simply and effective!

I still have two question:
- How the "rendered" attribute works? Is it not supposed to take only boolean values?
- How to have the "reRender" action in <apex:pageBlockSection> to be assigned to multiple section ids?

Thanks again.

All Answers

Neetu_BansalNeetu_Bansal
Hi Adelchi,

For rendering section on the basis of checkbox value, you can simply put rendered condition on the page block section and rerender them accordingly. Here is a sample code:
<apex:page standardController="Account">
	<apex:form>
		<apex:pageBlock id="pgBlock">
			<apex:pageBlockSection title="checkbox" >
				<apex:inputCheckBox value="{!Account.Match_Billing_Address__c}" >
					<apex:actionSupport reRender="pgBlock" event="onchange"/>
				</apex:inputCheckBox>
			</apex:pageBlockSection>
			<apex:pageBlockSection rendered="{!Account.Match_Billing_Address__c}" />
			<apex:pageBlockSection rendered="{!!Account.Match_Billing_Address__c}" />
		</apex:pageBlock>
	</apex:form>
</apex:page>

Thanks,
Neetu
Adelchi PelizzoAdelchi Pelizzo
Thanks Neetu,

It worked, simply and effective!

I still have two question:
- How the "rendered" attribute works? Is it not supposed to take only boolean values?
- How to have the "reRender" action in <apex:pageBlockSection> to be assigned to multiple section ids?

Thanks again.
This was selected as the best answer