Search code examples
javascriptjqueryrepeater

Not able to pass repeater Container.ItemIndex to javascript function as an argument


<script type="text/javascript" language="javascript">
function EnableDisablePkgInclusionDropDown(val) {

        alert("RowIndex: " + val);        
        var repeater = document.getElementById('<%= pnlrptPckgInclusions.ClientID %>');
        var dropdowns = repeater.getElementsByTagName('select');
        dropdowns[val].disabled = true;
        dropdowns[val].selectedIndex = "0";
}
</Script>

    <asp:Repeater runat="server" ID="rptPckgInclusions">
                                <HeaderTemplate>
                                    <table cellpadding="0" cellspacing="0" width="100%" border="0">
                                        <tr>

                                            <td align="left" style="width: 20%; text-align: left">
                                                Parent MarkUp
                                            </td>

                                        </tr>
                                    </table>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <table cellpadding="0" cellspacing="0" width="100%" border="0">
                                        <tr>                                            

                                            <td align="center" style="width: 20%;">
                                                <asp:CheckBox runat="server" ID="chkApplyParentMarkUp" OnClick="javascript:EnableDisablePkgInclusionDropDown(<%# Container.ItemIndex %>);"/>
                                            </td>

                                        </tr>
                                    </table>
                                </ItemTemplate>
                            </asp:Repeater>

I am trying to pass container.ItemIndex as an argument to javascript function on checkbox OnClick event to enable/disable few controls.But Its not showing the value in Javascript function.

Thanks in advance!


Solution

  • First of all be careful in components namings inside your JS function (pnlrptPckgInclusions != rptPckgInclusions)

    After this change you OnClick handler to this

    OnClick='<%# "javascript:EnableDisablePkgInclusionDropDown(" + Container.ItemIndex + ")" %>'
    

    It should help. Have a nice day !