You need to sign in to do that
Don't have an account?

Rerender Pageblocksection through visualforce checkbox via ajax
I am having a Checkbox on my vf page and what i want is when i click on my chekbox then only my certain pageblocksection/outpanel should be visible.
i am using following code on vf:
<apex:pageBlockSection title="Select Countries"> <apex:inputCheckbox value="{!reUSA}" label="USA"><apex:actionSupport event="onchange" reRender="USASection" id="Us"/></apex:inputCheckbox> </apex:pageBlockSection> <apex:outputPanel id="USASection" rendered="{!reUSA}"> <apex:inputField value="{!abc__c.myfield__c}" /></apex:outputPanel>
Apex code:
public Boolean reUSA{get; set;}
Now i have used various syntax for rendered attribute like: rendered="{!IF(reUSA==true,true,false)}"
OR this rendered={!reUSA=true} but the outpanel is not visible when i click on checkbox.
Onething i am confirmed about is when i click on checkbox ,its value is set to true...and i have even tried to display that value and i get true and onchanging the checkbox ,it shows me false and so on true..false.on further clicking..... but the thing i didn't understand is if its value sets to true/false..then y is it not able to substitute its "true/false" value in rendered attribute... in place of {!reUSA}.
Any suggestion wud be appreciated.. :)
put another output panel outside the one you are going to show accroding to checkbox value and rerender that.
<apex:pageBlockSection title="Select Countries">
<apex:inputCheckbox value="{!reUSA}" label="USA"><apex:actionSupport event="onchange" reRender="USASectionOuter" id="Us"/></apex:inputCheckbox>
</apex:pageBlockSection>
<apex:outputPanel id="USASectionOuter">
<apex:outputPanel id="USASection" rendered="{!reUSA}"> <apex:inputField value="{!abc__c.myfield__c}" /></apex:outputPanel>
</apex:outputPanel>
All Answers
put another output panel outside the one you are going to show accroding to checkbox value and rerender that.
<apex:pageBlockSection title="Select Countries">
<apex:inputCheckbox value="{!reUSA}" label="USA"><apex:actionSupport event="onchange" reRender="USASectionOuter" id="Us"/></apex:inputCheckbox>
</apex:pageBlockSection>
<apex:outputPanel id="USASectionOuter">
<apex:outputPanel id="USASection" rendered="{!reUSA}"> <apex:inputField value="{!abc__c.myfield__c}" /></apex:outputPanel>
</apex:outputPanel>
its because there is no html section with id "USASection" in the initial page render (as reUSA is false). so ajax cant identify which area to rerender