Amol Kadam Amol Kadam - 2 years ago 315
Javascript Question

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";

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

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

<table cellpadding="0" cellspacing="0" width="100%" border="0">

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


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!

Answer Source

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 !

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download