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
vanessa veronvanessa veron 

Function JS : checkbox is checked???

I have a function JS to check if a checkbox is checked, but does not work. Why?

<apex:page standardController="CronTrigger" >

<style type="text/css">
        .classeHoraire { width: 60px; }
        .classeBig { width: 600px; }
        .imageCenter {display: block; margin-left: auto; margin-right: auto;}
</style>
    
<script type="text/javascript">

function verify(){
var checkNomJob = '{!verifiyNomJob}';

if (document.getElementById("{!$Component.theform.block01.pageSess01.outputPane01.ckLun}").checked){
    alert("Messageee");
}
}
</script>

  <apex:form id="theform" > 
  <apex:PageBlock id="block01">

    Job Name.:&nbsp;<apex:inputText id="nomJobIP" value="{!nomJob}" />  
    <br /><br />
        
 <br/><br/>
 <apex:pageBlockSection columns="2" id="pageSess01">
    <apex:outputPanel id="outputPane01">
    
    <apex:inputCheckbox id="ckLun" value="{!checkLundi}" disabled="{!disableSemaineCheckModification}" />Lundi<br />
    <apex:inputCheckbox id="ckMar" value="{!checkMardi}" disabled="{!disableSemaineCheckModification}" />Mardi<br />
    </apex:outputPanel>
</apex:pageBlockSection>

.....

</apex:page>

Best Answer chosen by vanessa veron
Amritesh SahuAmritesh Sahu
Hi Venessa,

Replace the if statement with this
if(document.getElementById("{!$Component.theform.block01.pageSess01.ckLun}").checked)

Thanks

All Answers

Ramu_SFDCRamu_SFDC
I am afraid you cannot directly bind the value in the javascript, instead you can pass the value as a parameter to the verify function something as Function verify(checkstatus){.......}

Follow the procuedure explained in the below article

https://www.salesforce.com/us/developer/docs/pages/Content/pages_access.htm
vanessa veronvanessa veron
I will try this, thank you!
logontokartiklogontokartik
Hi Vanessa,

Can you try taking out the outputPane01 from your getElementById. Please try the below. 
if (document.getElementById("{!$Component.theform.block01.pageSess01.ckLun}").checked){
    alert("Messageee");
}

Thank you
vanessa veronvanessa veron
Tahnk you but It didn't work!
Amritesh SahuAmritesh Sahu
Hi Venessa,

Replace the if statement with this
if(document.getElementById("{!$Component.theform.block01.pageSess01.ckLun}").checked)

Thanks
This was selected as the best answer
vanessa veronvanessa veron
Thank you!!!!!!!!!!!!!!!!