I have the below code in a VF page and a simple javascript function to get the value of the checkbox. However, irrespective of whether the checkbox is checked or not I get a value of "on". How do I get the correct value of the checkbox ?

<apex:inputCheckbox id="cb1" value="{!cbVal1}" onchange="foo('{!$Component.cb1}', '{!$Component.cb2}',);
<apex:inputCheckbox id="cb2" value="{!cbVal2}" onchange="foo('{!$Component.cb1}', '{!$Component.cb2}',);

 <script type="text/javascript">        
     var foo = function foo( shp , con ){
        console.log( 'shp : ', document.getElementById(shp).value );
        console.log( 'con : ', document.getElementById(con).value );

Console output is :

"shp : " "on"

"con : " "on"


Found the answer - checked attribute gives the right value


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.