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
RajashriRajashri 

How to check checkbox on loading of VF page

Hi,

 

I have a requirement to automatically check the checkbox based on the leads names?

 

How can i do that through coding?

 

 

Anil MeghnathiAnil Meghnathi

In the constructor of your VFpage's Controller class, you have to set the value field of checkbox according to the name.

That's all.

amidstcloudamidstcloud

If there is getter setter for the checkbox  . assign the value to the them in the Constructor ..

 

Constructor (){

   inputcheckbox = true ;

 

You can perform the same thing with the Java script  too . 

RajashriRajashri

Thank you both!

 

Can you guys please provide an example so that i can get some idea?

 

I am new to it..

 

 

 

Anil MeghnathiAnil Meghnathi

Class

public class ControllerClass
{
public boolean cbvalue{get;set;}
public ControllerClass()
{
if(name.equals('SomeString')
cbvalue=true;
else
cbvalue=false;
}
}


Visualforce Page

<apex:page controller="ControllerClass">
<apex:form>
<apex:inputCheckBox value="{!cbvalue}"/>
</apex:form>
</apex:page>

 

This may solve your issue.

Thanks

RajashriRajashri

Hi Anil,

 

Thanks for quick response.

 

My code is as below. I want to change the value of Required__c based on the Role__c and i already have one standard controller in the class.i am using it for other purpose.as you suggested to add the boolean method but it is giving an error for sobject  so also i am using input field and not checkbox.

 

Can you please guide? Thanks for all your help.

 

 

<apex:page standardController="Detail__c"
        extensions="DetailController" >
  <apex:repeat value="{!appr}" var="item">
  <apex:pageBlockSection title="{!item.Role__c}" id="ItemBlock" columns="2">
           
                  <apex:inputField value="{!item.Required__c}" /></br>
                 


public with sharing class DetailController {
 public List<Appr__c> appr;
  public Detail__c Detail {get; set;}

 public DetailController (ApexPages.StandardController pCon) {
  Detail =(Detail__c)pCon.getRecord();
        Detail = [SELECT Id, Name FROM Detail__c
                                        WHERE ID = :Detail.Id];
      }

Anil MeghnathiAnil Meghnathi

Hi

Rajashri

 

First of all u have used  public List<Appr__c> appr in page.But you i dont see any assignmet to that list in class.please assign objects to that list

 

Thanks

ANil 

Anil MeghnathiAnil Meghnathi

<apex:page standardController="Detail__c" extensions="DetailController" >
  <apex:repeat value="{!appr}" var="item">
  <apex:pageBlockSection title="{!item.Role__c}" columns="2">
        <apex:inputField value="{!item.Required__c}" />

 </apex:pageBlockSection>

</apex:repeat>

</apex:page>

 

 

What is the field type of Required__c in sobject? Checkbox or Text.

RajashriRajashri

Hi Anil,

 

I have already assign the objects to list and it works fine.

 

Also Required__c object has the datatype checkbox.

 

 

RajashriRajashri

Can you please guide me how to proceed?

Anil MeghnathiAnil Meghnathi

If it is possible send me your complete new code of page and class in private message.

 

RajashriRajashri

Ok!! Sending