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
CritterCritter 

How to tell if checkbox on visualforce is checked

I need to do some processing based on whether a checkbox (inputcheckbox) is checked on page SAVE.

 

after searching around, all I have seen are references to using a wrapper class, which seems a little bit overboard for what I am looking to do.

 

Is there an easier way to tell if a checkbox is checked?

sfdcfoxsfdcfox

You don't need a wrapper class, just a controller variable:

 

public with sharing class mycontroller {
  public boolean mycheckval { get; set; }

  public mycontroller() {
    mycheckval = false;
  }

  public void dosomething() {
    if(mycheckval) {
      // yay, it's checked!
    }
  }
}

 

<apex:page controller="mycontroller">
<apex:form>
<apex:inputcheckbox value="{!mycheckval}" />
<apex:commandbutton value="Do Something" action="{!dosomething}" />
</apex:form>
</apex:page>

 

CritterCritter

Nice one mate. 

 

cheers.