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
Arundhati DebArundhati Deb 

how to default checkbox to true in visualforce and show the corresponding data accordingly

Hi,I have a vf page where there are multiple checkboxes. Once a checkbox is checked to true, the corresponding data is shown visible. This has been already done by us. But now we want to make checkbox default to true and also show the corresponding data as soon as the checkbox is checked by default:
VF page :

<div class="selectAllDiv">
                    <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId1','inputId2','inputId3','inputId4','inputId5','inputId6','inputId7','inputId8','inputId9',
                                                 'inputIdWirerd','inputIdHDWIC','inputIdDrwnWire', 'inputIdPcSt','inputIdSteelFab','inputIdCarpet')">
                        <apex:actionSupport event="onchange"  />
                    </apex:inputCheckbox><span>Select all</span>
                </div>
                <table class="blueTable" style="width:730px">
                    <tbody>
                        <tr>
                            <td>Product Type:</td>
                            <td>
                                <apex:inputCheckbox id="inputId1" selected ="true" value="{!Opportunity.barCheckBox__c}"  style="margin-left:8px">
                                <apex:actionSupport event="onchange"  />
                                </apex:inputCheckbox> Rebar
                                <br/>
                                <apex:inputCheckbox id="inputId2"  value="{!Opportunity.CutAndBend__c}" >
                                    <apex:actionSupport event="onchange"  />
                                </apex:inputCheckbox> Cut And Bend 
                                <br/>
                                <apex:inputCheckbox id="inputId3" value="{!Opportunity.PreFabCage__c}" > 
                                    <apex:actionSupport event="onchange"  />
                                </apex:inputCheckbox> Prefabricated Cage
                                <br/>
                                <apex:inputCheckbox id="inputId4" value="{!Opportunity.BorePileCage__c}" > 
                                    <apex:actionSupport event="onchange"  />
                                </apex:inputCheckbox> Bored Pile Cage
                                <br/>
                                <apex:inputCheckbox id="inputId5" styleClass="chkwc" onclick="disableMPCWoC(this,'inputId6')" value="{!Opportunity.Micro_Pile_Cage_with_centraliser__c}"   > 
                                    <apex:actionSupport event="onchange"  />
                                </apex:inputCheckbox> Micro Pile Cage (w/ centraliser)
                                <br/>
                                <apex:inputCheckbox id="inputId6" styleClass="chkwoc" onclick="disableMPCWC(this,'inputId5')" value="{!Opportunity.Micro_Pile_Cage_w_o_centraliser__c}"   > 
                                    <apex:actionSupport event="onchange"  />
                                </apex:inputCheckbox> Micro Pile Cage (w/o centraliser)
                                <br/>
                                <apex:inputCheckbox id="inputId7" value="{!Opportunity.Coupler1__c}"   > 
                                    <apex:actionSupport event="onchange" />
                                </apex:inputCheckbox> Coupler
                                <br/>
                            </td>
                            <td><apex:inputCheckbox id="inputId8" value="{!Opportunity.Deformed_Bar_In_Coil__c}" style="margin-left:8px">
                                <apex:actionSupport event="onchange"  />
                                </apex:inputCheckbox> Deformed Bar in Coil 
                                <br/>
                                <apex:inputCheckbox id="inputId9" value="{!Opportunity.Deformed_Bar_In_Coil_Semi__c}" >
                                    <apex:actionSupport event="onchange"  /> 
                                </apex:inputCheckbox> Deformed Bar in Coil (semi)
                                <br/>
                                <apex:inputCheckbox id="inputIdWirerd" value="{!Opportunity.Wire_Rod__c}" > 
                                    <apex:actionSupport event="onchange"  />
                                </apex:inputCheckbox> Wire Rod
                                <br/>
                                <apex:inputCheckbox id="inputIdHDWIC" value="{!Opportunity.Hard_drawn_wire_in_Coil__c}" > 
                                    <apex:actionSupport event="onchange"  />
                                </apex:inputCheckbox> Hard Drawn wire in Coil
                                <br/>
                                <apex:inputCheckbox id="inputIdDrwnWire" value="{!Opportunity.Hard_drawn_wire__c}" > 
                                    <apex:actionSupport event="onchange"  />
                                </apex:inputCheckbox> Hard Drawn wire
                                <br/>
                                <apex:inputCheckbox id="inputIdPcSt" value="{!Opportunity.PC_Strand__c}"   > 
                                    <apex:actionSupport event="onchange" />
                                </apex:inputCheckbox> PC Strand
                                <br/>
                                <br/>
                            </td>
                            <td><apex:inputCheckbox id="inputIdSteelFab" value="{!Opportunity.Steel_Fabric_Products__c}" style="margin-left:8px;">
                                <apex:actionSupport event="onchange"  />
                                </apex:inputCheckbox> Steel Fabric Products
                                <br/>
                                <apex:inputCheckbox id="inputIdCarpet" value="{!Opportunity.Carpet__c}"> 
                                    <apex:actionSupport event="onchange"  />
                                </apex:inputCheckbox> Carpet
                                <br/><br/><br/><br/><br/><br/>
                            </td>
                        </tr>
                    </tbody>
                </table><br/>
                <apex:outputPanel rendered="{!Opportunity.barCheckBox__c}" id="barCheckBox">
                    <table class="blueTable" style="width:730px">
                        <thead>
                            <tr>
                                <th>Rebar (w/o DS) in mm </th>
                                <th>Volume (mt)</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>8</td>
                                <td><apex:inputField value="{!Opportunity.Material_w_o_DS_8__c}"/></td>
                            </tr>
                            <tr>
                                <td>10,13 </td>
                                <td><apex:inputField value="{!Opportunity.Material_w_o_DS_10_13_volume__c}"/></td>
                            </tr>
                            <tr>
                                <td>28,40 </td>
                                <td><apex:inputField value="{!Opportunity.Material_w_o_DS_28_40_volume__c}"/></td>
                            </tr>
                            <tr>
                                <td> 16,20,25,32</td>
                                <td><apex:inputField value="{!Opportunity.Material_w_o_DS_16_20_25_32_volume__c}"/></td>
                            </tr>
                            <tr>
                                <td> 50 </td>
                                <td><apex:inputField value="{!Opportunity.Material_w_o_DS_50_Volume__c}"/></td>
                            </tr>
                            <tr>
                                <td><b>Total Rebar &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</b></td>
                                <td><apex:inputField value="{!Opportunity.Total_w_o_DS__c}"/></td>
                            </tr>
                        </tbody>
                    </table>
                </apex:outputPanel><br/>
Somya TiwariSomya Tiwari
This can be achieved simply by provding checked=true as default for that particular checkbox. When the user will uncheck the checkbox, its value will change, hence during input, that's not an issue.
Arundhati DebArundhati Deb
Yes agreed , that was already done by me but the event which we are using is  <apex:actionSupport event="onchange"  /> and hence the fields related to the checkbox do not show when the record is created. I want to do it in such a way that when record is created, the checkbox is checked and its corresponding data is also displayed.