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
Mak OneMak One 

How to iterate through each element in pageBlockTable?

I have to iterate through each element in pageBlockTable and if no element's checkbox is checked then I have to disable Submit Button in runtime without submitting the form.

Below is my snippet of Visualforce page:
The line:
var curr=document.getElementbyID('{!$Component.formId.pageBlockId.pageBlockTableId[i].headerId.checkBoxId}').value;
is having error: Unknown property 'StandardController.i'
Then how to get checked of each element in pageBlockTable.
What is the correct way rather than work around solution? Without changing pageBlockTable and without using any 3rd party tool.

<apex:form id="formId">
                <apex:pageBlock id="pageBlockId">
                   <apex:pageBlockTable value="{!displayToSelect}" var="disp" id="pageBlockTableId">
                       <apex:column headerValue="Commercial Reference" style="text-align:center;">
                                <apex:outputLabel value="{!disp.cr.Field1__c}"/>
                       </apex:column>

                       <apex:column headerValue="Status">
                                <apex:outputText value="{!disp.status}"/>
                       </apex:column>
                     
                       <apex:column headerValue="Add This?" id="headerId">
                            <apex:inputCheckbox value="{!disp.check}" onChange="checkEnableDisable()" id="checkboxId"/>
                       </apex:column>

                   </apex:pageBlockTable>
                 
             </apex:pageBlock>
                   <apex:commandButton value="Submit" action="{!submitRecords}" disabled="{!disableSubmit}" id="submitId"/>
</apex:form>

<script>

checkEnableDisable(){
    var allUnchecked=true;
    var list=document.getElementbyID('{!$Component.formId.pageBlockId.pageBlockTableId}');
    for (var i=0;i<list.length;i++){
        var curr=document.getElementbyID('{!$Component.formId.pageBlockId.pageBlockTableId[i].headerId.checkBoxId}').value;
        if (curr==true){
            allunchecked=false;
        }
    }
    document.getElementbyID('{!$Component.formId.submitId}').setAttribute('disabled',alluNchecked);
}

</script>
kiranmutturukiranmutturu
onChange="checkEnableDisable(this.id)"... get the id of the component like this by passing this.id
Mak OneMak One
It will give the id of commandButton I think.
How to access table values from that?