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
Alexander AtkinsonAlexander Atkinson 

Visual Force Page: Check all boxes doesn't trigger their "OnChange"

I have a table of items. Each item can be selected or checked with a checkbox, and an OnChange is triggered to pass its ID to Apex for a query that will quote the selected items.
This works all fine for individual checking. However I just added a page component that checks all the items if the "Select All" box is checked. This "works" also, it ticks all the boxes on the table. However the OnChange is not triggered so no ID's are passed to Apex for the query resulting in no quote data.

Visual Force Page Snippet:
<apex:page>
    <table>
        <tr class="headerRow">
            <th style="font-size: 14px; font-weight: bold; text-align: center" width="4%">
                <br/>Select<br/>
                <c:CheckAllOrNone />
            </th>
            </tr>
            <apex:repeat value="{!data}" var="Results">
            <tr>
                <td style="text-align: center" width="4%"><input type="checkbox" value="{!Results.Id}" onChange="quotesCheck('{!Results.id}', this.checked);" /></td>
            </tr>
        </apex:repeat>
    </table>
</apex:page>
Visual Component: 
<apex:component >
    <script>
    function cvCheckAllOrNone(allOrNoneCheckbox) {

        // Find parent table
        var container = allOrNoneCheckbox;
        while (container.tagName != "TABLE") {
            container = container.parentNode;
        }

        // Switch all checkboxes
        var inputs = container.getElementsByTagName("input");
        var checked = allOrNoneCheckbox.checked;
        for (var i = 0; i < inputs.length; i++) { 
            var input = inputs.item(i);
            if (input.type == "checkbox") {
                if (input != allOrNoneCheckbox) {
                    input.checked = checked;
                }
            }
        }
    }
    </script>

    <apex:inputCheckbox onclick="cvCheckAllOrNone(this)" title="Toggle All Rows"/>
</apex:component>

Apex Snippet
public PageReference addQuotesToChecked()
{
    string quoteId = Apexpages.currentPage().getParameters().get('quoteId');
    string chkValue = Apexpages.currentPage().getParameters().get('chkValue');
    System.debug('quoteId '+quoteId);
    System.debug('chkValue '+chkValue);
    if(checkedQuotes ==null)
    {
        checkedQuotes= new List<id>();
        checkedQuotes.add(quoteId);
    }
    else
    {
        if(chkValue=='true')
        {
            checkedQuotes.add(quoteId);
        }
        else
        {
           integer i= checkedQuotes.indexOf(quoteId);
            checkedQuotes.remove(i);
        }

    }
    integer i=checkedQuotes.size();

    return null;
}

The Apex code works, and so does the visual force code. Ticking individually passes data. Mass checking with the page component however doesn't.


 
Alexander AtkinsonAlexander Atkinson
I'm guessing something along the lines of :
 
input.OnChange = quotesCheck('{!Results.id}', this.checked);


 
Alexander AtkinsonAlexander Atkinson
I've updated the page component :
 
input.checked = checked;                                
    if(input.checked = checked)
    {
        input.onChange = quotesCheck(input.value, input.checked);    
    }
This almost fixes the problem. One last issue however is only one value is passed to apex.