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
MagnetismMagnetism 

Inputcheckbox value returns a value 'on' upon selection

I have three fields I am currently trying to get results on and after that I am going to implement the same methods to work on the rest of the fields. So, I have two picklist fields of single selects and a inputcheckbox. I am calling the RemoteAction method in controller from javascript to get the user selected values back to the controller. From there I will get use those values to do some dml operations. So, for the two picklist fields, I am able to get the values back to controller in the form of the Id's. But for the inputcheckbox the value is returning to be false even though it is selected. And another thing I noticed was, when I alert({!inputcheckbox}); value in the page, the same field value returns "on". I am looking for some help. I greatly appreciate it.
Grazitti TeamGrazitti Team
Hi,

Inputcheckbox returns a boolean value true or false and when you pass a property in inputcheckbox value attribute then you get the value of checkbox in controller. Forex.

your page contains:

<apex:page controller="bckbtn">
    <apex:form >
        <apex:commandButton value="Back" action="{!back}"/>
        <apex:inputcheckbox value="{!chckboxvalue}"/>
    </apex:form>
</apex:page>

and controller is: 

public class bckbtn{
    public String chckboxvalue{get;set;}
    public bckbtn(){
        system.debug('chckboxvalue---->' + chckboxvalue);
    }
    public pageReference back(){
        system.debug('chckboxvalue---->' + chckboxvalue);
        Pagereference pref = new Pagereference('http://google.com');
        pref.setRedirect(true);
        return pref;
    }
}

when you see your debug log on first go then value is null and when select the checkbox and click on back button then value of chckboxvalue variable in controller changes to TRUE 

let us know if you have any question .
please don't Forget to Mark this as your best answer if it works fine for you

Regards,
Grazitti Team
Web: www.grazitti.com.
Avidev9Avidev9
Ok looks like some js issue. I will suggest you to use JQuery to pick values from the page if you are planning to user Remoting. This way it will be really easier to handle the Ids and values as well
MagnetismMagnetism
Avidev9:  it's exactly javascript issue and I got the solution . 
In  document.getElementById('Id').Value;  I had to replace '.value 'with '.checked' . It worked fine. But I consider using jquery to do the same. I will explore that too. Thanks for your input. Thank you all.