I'm calling javascript method from apex:inputcheckbox but facing an error:

Uncaught ReferenceError: disableChebox is not defined

Please help me, as I'm not able to understand why I receive this error.

code :

<apex:pageblockTable value="{!DisplayServices}" var="d" id="pt1">
    <apex:column headerValue="Select Included Services" id="col1">
        <apex:inputCheckbox value="{!d.isSelected}" id="chcbox" onclick="disableChebox('{!mp[d.serviceName]}','{!d.serviceName}','{!$Component.chcbox}');myFunction('{!mp[d.serviceName]}');"/>

<scrip type="text/javascript">
function disableChebox(xx, name, selectedId){
     var x=document.getElementsByName('abc')[xx];
     if(x.disabled == false){
     x.disabled = !x.disabled;
     var selectedd = document.getElementById(selectedId);
     if(name== "Advisory Services" && selectedd.checked){
         if(document.getElementById("pg:form:pgbr:rp:2:ae") != null){
             document.getElementById("pg:form:pgbr:rp:2:ae").style.display = 'block';
    if(name== "Advisory Services" && !selectedd.checked){
        if(document.getElementById("pg:form:pgbr:rp:2:ae") != null){
            document.getElementById("pg:form:pgbr:rp:2:ae").style.display = 'none';

function myFunction(xx){
    var total=0;
    var x=document.getElementsByName('abc');
    for(var a=0;a<x.length;a++){
        total = parseInt(total,10)+parseInt(x[a].value,10);
    if(total >100){
        showMessage('ERROR', 'Total is greater than 100.Current percentage value is '+total);
        showMessage('Clear', '');
    return false;


NOTE :I also tried by giving simple javascript method which will execute just alert statement, then also I got same error.


Honestly you would be better off doing this with unobtrusive listeners so you do not have to add functions to the window. I usually use jQuery just to ensure cross-browser support. Also take a look at Self Executing Anonymous Functions

<apex:inputCheckbox className="myCheckbox" />
    (function ($) {
        $(function () {
            $('.myCheckbox').click(function () {
                // do stuff

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.