Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript with gridview

Status
Not open for further replies.

Bhani

Programmer
Jan 3, 2011
4
US
I have a gridview which has the first Item Template as a checkbox (CheckBoxActiveClient), then it has some BoundFields that display data from the database, and the last column is a textbox item template (Copies) that takes input from the user. Using javascript, I want to disable the the 'Copies' textbox if the' CheckBoxActiveClient' is unchecked in that gridview row, and enable it if 'CheckBoxActiveClient' is checked. I know how to do it using autopostback, but I want to do it using javascript, because autopostback is slow response. Please check my markup and the javascript and suggest correction. Thia javascript is not working.


Thank You for your help in advance.

Code:
<head runat="server">
    <link href="Styles/StyleSheet1.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
        var TotalChkBx;
        var Counter;
        var ctrChecked;

        function HeaderClick(CheckBox) 
        {
           .....
            }


            function TogleCopies(CheckBox) 
           {
               var gridViewCtlId = '<%=this.gvClients.ClientID%>';
               var grid = document.getElementById(gridViewCtlId);
               var gridLength = grid.rows.length;
               for (var i = 1; i < gridLength - 1; i++) 
               {
                //tb = document.getElementById('Copies');
                   //cb = document.getElementById('CheckBoxActiveClient');
                   cb = grid.rows[i].cells[0];
                   tb = grid.rows[i].cells[4];
                   if (cb.Checked = true) {
                       tb.Enabled = true;
                   }
                   else
                   {tb.Enabled = false; }
               }
           }    
         
         </script>


</head>

<body>
    <form id="form1" runat="server">
...


<asp:GridView ID="gvClients" runat="server" EmptyDataText="No Clients found" AutoGenerateColumns="False"
                                    EnableViewState="false" AllowSorting="true" AllowPaging="true" PageSize="20"
                                    OnPageIndexChanging="gridView_PageIndexChanging" CssClass="mGrid" PagerStyle-CssClass="pgr"
                                    AlternatingRowStyle-CssClass="alt" OnRowDataBound = "gvClients_ShowClientStatus" >
                                    <PagerSettings Position="Bottom" Mode="NumericFirstLast" FirstPageText="First"
                                        LastPageText="Last" NextPageText="Next" PreviousPageText="Prev" />
                                    <PagerStyle HorizontalAlign="Center" />
                                    <Columns>
                                        <asp:TemplateField>
                                            <HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" />
                                            <HeaderTemplate>
                                                <asp:CheckBox ID="chkBxHeader" onclick="javascript:HeaderClick(this);" runat="server"
                                                    ToolTip="Click to Select/Un-Select All" />
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <asp:CheckBox ID="CheckBoxActiveClient" onClick = "javascript:TogleCopies(this);" runat="server" Enabled="true" />
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField Visible="false">
                                            <ItemTemplate>
                                                <asp:Label ID="ClientName" runat="server" Text='<%# Eval("ClientName") %>' Visible="false" ></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField Visible="false">
                                            <ItemTemplate>
                                                <asp:Label ID="Active" runat="server" Text='<%# Eval("Active") %>' Visible="false"></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:BoundField HeaderText="Company Name" DataField="CompanyName" ItemStyle-HorizontalAlign="left" />
                                        <asp:BoundField HeaderText="Client Name" DataField="ClientName" ItemStyle-HorizontalAlign="left" />
                                        <asp:BoundField HeaderText="Active" DataField="Active" ItemStyle-HorizontalAlign="left" />
                                        <asp:TemplateField>
                                        <HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" />
                                            <HeaderTemplate>
                                                <asp:Label ID="HCopies" runat="server" Text = "#Copies" />
                                            </HeaderTemplate>
                                            <ItemStyle HorizontalAlign = "Center" />
                                            <ItemTemplate >
                                                <asp:Textbox ID="Copies" runat="server" Text='<%# Eval("Copies") %>' Width = "20" OnTextChanged = "Validate" AutoPostBack = "true"></asp:Textbox>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                        <ItemStyle HorizontalAlign = "Center" />
                                            <ItemTemplate >
                                                <asp:Label ID="InValid" runat="server" Text='' Width = "20"></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                    </Columns>
                                </asp:GridView>


 
Please always post the resultant HTML (from the browser view source) and not the ASP code. As you may find that it will be easier to get answers that way. Otherwise you rely on people actually understanding the ASP in a JS forum which may or may not happen.

It seems you are already doing the enabling/disabling via JS.

Code:
 function TogleCopies(CheckBox)
           {
               var gridViewCtlId = '<%=this.gvClients.ClientID%>';
               var grid = document.getElementById(gridViewCtlId);
               var gridLength = grid.rows.length;
               for (var i = 1; i < gridLength - 1; i++)
               {
                //tb = document.getElementById('Copies');
                   //cb = document.getElementById('CheckBoxActiveClient');
                   cb = grid.rows[i].cells[0];
                   tb = grid.rows[i].cells[4];
                   if (cb.Checked = true) {
                       tb.Enabled = true;
                   }
                   else
                   {tb.Enabled = false; }
               }
           }    
         
         </script>


...

<asp:CheckBox ID="CheckBoxActiveClient" onClick = "javascript:TogleCopies(this);" runat="server" Enabled="true" />

So I'm not sure what you are after.




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Thanks vacunita. I want to use this javascript, but it is not working. Nothing happens when I check/uncheck the ActiveClientCheckbox.

Here is the corresponding generated html source from browser ->view source.
Thanks for your help.

Code:
<table class="mGrid" cellspacing="0" rules="all" border="1" id="gvClients" style="border-collapse:collapse;">

		<tr>
			<th align="left" valign="middle" scope="col">
                                                <span title="Click to Select/Un-Select All"><input id="gvClients_ctl01_chkBxHeader" type="checkbox" name="gvClients$ctl01$chkBxHeader" onclick="javascript:HeaderClick(this);" /></span>
                                            </th><th scope="col">Company Name</th><th scope="col">Client Name</th><th scope="col">Active</th><th align="left" valign="middle" scope="col">
                                                <span id="gvClients_ctl01_HCopies">#Copies</span>
                                            </th><th scope="col">&nbsp;</th>
		</tr><tr>

			<td>
                                                <span style="background-color:GreenYellow;"><input id="gvClients_ctl02_CheckBoxActiveClient" type="checkbox" name="gvClients$ctl02$CheckBoxActiveClient" checked="checked" onclick="javascript:TogleCopies(this);" /></span>
                                            </td><td align="left">&nbsp;</td><td align="left">C094</td><td align="left">True</td><td align="center">
                                                <input name="gvClients$ctl02$Copies" type="text" value="1" onchange="javascript:setTimeout('__doPostBack(\'gvClients$ctl02$Copies\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="gvClients_ctl02_Copies" style="width:20px;" />
                                            </td><td align="center">
                                                <span id="gvClients_ctl02_InValid" style="display:inline-block;width:20px;"></span>
                                            </td>
		</tr><tr class="alt">

			<td>
                                                <span style="background-color:White;"><input id="gvClients_ctl03_CheckBoxActiveClient" type="checkbox" name="gvClients$ctl03$CheckBoxActiveClient" onclick="javascript:TogleCopies(this);" /></span>
                                            </td><td align="left">1st Choice Med &amp; Cancer Care</td><td align="left">C469</td><td align="left">False</td><td align="center">
                                                <input name="gvClients$ctl03$Copies" type="text" value="1" onchange="javascript:setTimeout('__doPostBack(\'gvClients$ctl03$Copies\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="gvClients_ctl03_Copies" disabled="disabled" style="width:20px;" />
                                            </td><td align="center">
                                                <span id="gvClients_ctl03_InValid" style="display:inline-block;width:20px;"></span>

                                            </td>
		</tr><tr>
			<td>
                                                <span style="background-color:GreenYellow;"><input id="gvClients_ctl04_CheckBoxActiveClient" type="checkbox" name="gvClients$ctl04$CheckBoxActiveClient" checked="checked" onclick="javascript:TogleCopies(this);" /></span>
                                            </td><td align="left">21st Century Oncology</td><td align="left">C364</td><td align="left">True</td><td align="center">
                                                <input name="gvClients$ctl04$Copies" type="text" value="2" onchange="javascript:setTimeout('__doPostBack(\'gvClients$ctl04$Copies\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="gvClients_ctl04_Copies" style="width:20px;" />
                                            </td><td align="center">

                                                <span id="gvClients_ctl04_InValid" style="display:inline-block;width:20px;"></span>
                                            </td>
		</tr><tr class="alt">
			<td>
                                                <span style="background-color:GreenYellow;"><input id="gvClients_ctl05_CheckBoxActiveClient" type="checkbox" name="gvClients$ctl05$CheckBoxActiveClient" checked="checked" onclick="javascript:TogleCopies(this);" /></span>
                                            </td><td align="left">Acadiana Pathology Services, AMC</td><td align="left">C577</td><td align="left">True</td><td align="center">
                                                <input name="gvClients$ctl05$Copies" type="text" value="1" onchange="javascript:setTimeout('__doPostBack(\'gvClients$ctl05$Copies\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="gvClients_ctl05_Copies" style="width:20px;" />

                                            </td><td align="center">
                                                <span id="gvClients_ctl05_InValid" style="display:inline-block;width:20px;"></span>
                                            </td>
		</tr><tr>
			<td>
                                                <span style="background-color:GreenYellow;"><input id="gvClients_ctl06_CheckBoxActiveClient" type="checkbox" name="gvClients$ctl06$CheckBoxActiveClient" checked="checked" onclick="javascript:TogleCopies(this);" /></span>
                                            </td><td align="left">Adams &amp; Bridger</td><td align="left">C123</td><td align="left">True</td><td align="center">

                                                <input name="gvClients$ctl06$Copies" type="text" value="1" onchange="javascript:setTimeout('__doPostBack(\'gvClients$ctl06$Copies\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="gvClients_ctl06_Copies" style="width:20px;" />
                                            </td><td align="center">
                                                <span id="gvClients_ctl06_InValid" style="display:inline-block;width:20px;"></span>
                                            </td>
		</tr><tr class="alt">
			<td>
                                                <span style="background-color:White;"><input id="gvClients_ctl07_CheckBoxActiveClient" type="checkbox" name="gvClients$ctl07$CheckBoxActiveClient" onclick="javascript:TogleCopies(this);" /></span>
                                            </td><td align="left">Advanced Hematology and Oncology Centers-Deland</td><td align="left">C442</td><td align="left">False</td><td align="center">

                                                <input name="gvClients$ctl07$Copies" type="text" value="1" onchange="javascript:setTimeout('__doPostBack(\'gvClients$ctl07$Copies\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="gvClients_ctl07_Copies" disabled="disabled" style="width:20px;" />
                                            </td><td align="center">
                                                <span id="gvClients_ctl07_InValid" style="display:inline-block;width:20px;"></span>
                                            </td>
		</tr><tr>
			<td>
                                                <span style="background-color:GreenYellow;"><input id="gvClients_ctl08_CheckBoxActiveClient" type="checkbox" name="gvClients$ctl08$CheckBoxActiveClient" checked="checked" onclick="javascript:TogleCopies(this);" /></span>
                                            </td><td align="left">Advanced Hematology and Oncology Centers-Lake Mary</td><td align="left">C443</td><td align="left">True</td><td align="center">

                                                <input name="gvClients$ctl08$Copies" type="text" value="1" onchange="javascript:setTimeout('__doPostBack(\'gvClients$ctl08$Copies\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="gvClients_ctl08_Copies" style="width:20px;" />
                                            </td><td align="center">
                                                <span id="gvClients_ctl08_InValid" style="display:inline-block;width:20px;"></span>
                                            </td>
		</tr><tr class="alt">
			<td>
                                                <span style="background-color:GreenYellow;"><input id="gvClients_ctl09_CheckBoxActiveClient" type="checkbox" name="gvClients$ctl09$CheckBoxActiveClient" checked="checked" onclick="javascript:TogleCopies(this);" /></span>
                                            </td><td align="left">Advanced Hematology and Oncology Centers-Orange Ci</td><td align="left">C444</td><td align="left">True</td><td align="center">

                                                <input name="gvClients$ctl09$Copies" type="text" value="1" onchange="javascript:setTimeout('__doPostBack(\'gvClients$ctl09$Copies\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="gvClients_ctl09_Copies" style="width:20px;" />
                                            </td><td align="center">
                                                <span id="gvClients_ctl09_InValid" style="display:inline-block;width:20px;"></span>
                                            </td>
		</tr><tr>
			<td>
                                                <span style="background-color:GreenYellow;"><input id="gvClients_ctl10_CheckBoxActiveClient" type="checkbox" name="gvClients$ctl10$CheckBoxActiveClient" checked="checked" onclick="javascript:TogleCopies(this);" /></span>
                                            </td><td align="left">Alameda County Medical Center</td><td align="left">C456</td><td align="left">True</td><td align="center">

                                                <input name="gvClients$ctl10$Copies" type="text" value="1" onchange="javascript:setTimeout('__doPostBack(\'gvClients$ctl10$Copies\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="gvClients_ctl10_Copies" style="width:20px;" />
                                            </td><td align="center">
                                                <span id="gvClients_ctl10_InValid" style="display:inline-block;width:20px;"></span>
                                            </td>
		</tr><tr class="alt">
			<td>
                                                <span style="background-color:GreenYellow;"><input id="gvClients_ctl11_CheckBoxActiveClient" type="checkbox" name="gvClients$ctl11$CheckBoxActiveClient" checked="checked" onclick="javascript:TogleCopies(this);" /></span>
                                            </td><td align="left">Albemarle Hospital</td><td align="left">C663</td><td align="left">True</td><td align="center">

                                                <input name="gvClients$ctl11$Copies" type="text" value="1" onchange="javascript:setTimeout('__doPostBack(\'gvClients$ctl11$Copies\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="gvClients_ctl11_Copies" style="width:20px;" />
                                            </td><td align="center">
                                                <span id="gvClients_ctl11_InValid" style="display:inline-block;width:20px;"></span>
                                            </td>
		</tr><tr>
			<td>
                                                <span style="background-color:GreenYellow;"><input id="gvClients_ctl12_CheckBoxActiveClient" type="checkbox" name="gvClients$ctl12$CheckBoxActiveClient" checked="checked" onclick="javascript:TogleCopies(this);" /></span>
                                            </td><td align="left">Alton Memorial Hospital</td><td align="left">C517</td><td align="left">True</td><td align="center">

                                                <input name="gvClients$ctl12$Copies" type="text" value="1" onchange="javascript:setTimeout('__doPostBack(\'gvClients$ctl12$Copies\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="gvClients_ctl12_Copies" style="width:20px;" />
                                            </td><td align="center">
                                                <span id="gvClients_ctl12_InValid" style="display:inline-block;width:20px;"></span>
                                            </td>
		</tr><tr class="alt">
			<td>
                                                <span style="background-color:GreenYellow;"><input id="gvClients_ctl13_CheckBoxActiveClient" type="checkbox" name="gvClients$ctl13$CheckBoxActiveClient" checked="checked" onclick="javascript:TogleCopies(this);" /></span>
                                            </td><td align="left">Anderson Oncology</td><td align="left">C291</td><td align="left">True</td><td align="center">

                                                <input name="gvClients$ctl13$Copies" type="text" value="1" onchange="javascript:setTimeout('__doPostBack(\'gvClients$ctl13$Copies\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="gvClients_ctl13_Copies" style="width:20px;" />
                                            </td><td align="center">
                                                <span id="gvClients_ctl13_InValid" style="display:inline-block;width:20px;"></span>
                                            </td>
		</tr><tr>
			<td>
                                                <span style="background-color:GreenYellow;"><input id="gvClients_ctl14_CheckBoxActiveClient" type="checkbox" name="gvClients$ctl14$CheckBoxActiveClient" checked="checked" onclick="javascript:TogleCopies(this);" /></span>
                                            </td><td align="left">Arizona Center for Hematology &amp; Oncology, PLC</td><td align="left">C375</td><td align="left">True</td><td align="center">

                                                <input name="gvClients$ctl14$Copies" type="text" value="1" onchange="javascript:setTimeout('__doPostBack(\'gvClients$ctl14$Copies\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="gvClients_ctl14_Copies" style="width:20px;" />
                                            </td><td align="center">
                                                <span id="gvClients_ctl14_InValid" style="display:inline-block;width:20px;"></span>
                                            </td>
		</tr><tr class="alt">
			<td>
                                                <span style="background-color:GreenYellow;"><input id="gvClients_ctl15_CheckBoxActiveClient" type="checkbox" name="gvClients$ctl15$CheckBoxActiveClient" checked="checked" onclick="javascript:TogleCopies(this);" /></span>
                                            </td><td align="left">Arizona Center for Hematology and Oncology, PLC</td><td align="left">C407</td><td align="left">True</td><td align="center">

                                                <input name="gvClients$ctl15$Copies" type="text" value="1" onchange="javascript:setTimeout('__doPostBack(\'gvClients$ctl15$Copies\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="gvClients_ctl15_Copies" style="width:20px;" />
                                            </td><td align="center">
                                                <span id="gvClients_ctl15_InValid" style="display:inline-block;width:20px;"></span>
                                            </td>
		</tr><tr>
			<td>
                                                <span style="background-color:GreenYellow;"><input id="gvClients_ctl16_CheckBoxActiveClient" type="checkbox" name="gvClients$ctl16$CheckBoxActiveClient" checked="checked" onclick="javascript:TogleCopies(this);" /></span>
                                            </td><td align="left">Arizona Oncology - Phoenix</td><td align="left">C420</td><td align="left">True</td><td align="center">

                                                <input name="gvClients$ctl16$Copies" type="text" value="1" onchange="javascript:setTimeout('__doPostBack(\'gvClients$ctl16$Copies\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="gvClients_ctl16_Copies" style="width:20px;" />
                                            </td><td align="center">
                                                <span id="gvClients_ctl16_InValid" style="display:inline-block;width:20px;"></span>
                                            </td>
		</tr><tr class="alt">
			<td>
                                                <span style="background-color:GreenYellow;"><input id="gvClients_ctl17_CheckBoxActiveClient" type="checkbox" name="gvClients$ctl17$CheckBoxActiveClient" checked="checked" onclick="javascript:TogleCopies(this);" /></span>
                                            </td><td align="left">Arizona Oncology - Prescott Valley</td><td align="left">C475</td><td align="left">True</td><td align="center">

                                                <input name="gvClients$ctl17$Copies" type="text" value="1" onchange="javascript:setTimeout('__doPostBack(\'gvClients$ctl17$Copies\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="gvClients_ctl17_Copies" style="width:20px;" />
                                            </td><td align="center">
                                                <span id="gvClients_ctl17_InValid" style="display:inline-block;width:20px;"></span>
                                            </td>
		</tr><tr>
			<td>
                                                <span style="background-color:GreenYellow;"><input id="gvClients_ctl18_CheckBoxActiveClient" type="checkbox" name="gvClients$ctl18$CheckBoxActiveClient" checked="checked" onclick="javascript:TogleCopies(this);" /></span>
                                            </td><td align="left">Ashford Institute of Hematology &amp; Oncology</td><td align="left">C656</td><td align="left">True</td><td align="center">

                                                <input name="gvClients$ctl18$Copies" type="text" value="1" onchange="javascript:setTimeout('__doPostBack(\'gvClients$ctl18$Copies\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="gvClients_ctl18_Copies" style="width:20px;" />
                                            </td><td align="center">
                                                <span id="gvClients_ctl18_InValid" style="display:inline-block;width:20px;"></span>
                                            </td>
		</tr><tr class="alt">
			<td>
                                                <span style="background-color:GreenYellow;"><input id="gvClients_ctl19_CheckBoxActiveClient" type="checkbox" name="gvClients$ctl19$CheckBoxActiveClient" checked="checked" onclick="javascript:TogleCopies(this);" /></span>
                                            </td><td align="left">Athens Regional Medical Center</td><td align="left">C183</td><td align="left">True</td><td align="center">

                                                <input name="gvClients$ctl19$Copies" type="text" value="1" onchange="javascript:setTimeout('__doPostBack(\'gvClients$ctl19$Copies\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="gvClients_ctl19_Copies" style="width:20px;" />
                                            </td><td align="center">
                                                <span id="gvClients_ctl19_InValid" style="display:inline-block;width:20px;"></span>
                                            </td>
		</tr><tr>
			<td>
                                                <span style="background-color:GreenYellow;"><input id="gvClients_ctl20_CheckBoxActiveClient" type="checkbox" name="gvClients$ctl20$CheckBoxActiveClient" checked="checked" onclick="javascript:TogleCopies(this);" /></span>
                                            </td><td align="left">Atlanta Cancer Care</td><td align="left">C185</td><td align="left">True</td><td align="center">

                                                <input name="gvClients$ctl20$Copies" type="text" value="1" onchange="javascript:setTimeout('__doPostBack(\'gvClients$ctl20$Copies\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="gvClients_ctl20_Copies" style="width:20px;" />
                                            </td><td align="center">
                                                <span id="gvClients_ctl20_InValid" style="display:inline-block;width:20px;"></span>
                                            </td>
		</tr><tr class="alt">
			<td>
                                                <span style="background-color:GreenYellow;"><input id="gvClients_ctl21_CheckBoxActiveClient" type="checkbox" name="gvClients$ctl21$CheckBoxActiveClient" checked="checked" onclick="javascript:TogleCopies(this);" /></span>
                                            </td><td align="left">Atlanta Cancer Care</td><td align="left">C563</td><td align="left">True</td><td align="center">

                                                <input name="gvClients$ctl21$Copies" type="text" value="1" onchange="javascript:setTimeout('__doPostBack(\'gvClients$ctl21$Copies\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="gvClients_ctl21_Copies" style="width:20px;" />
                                            </td><td align="center">
                                                <span id="gvClients_ctl21_InValid" style="display:inline-block;width:20px;"></span>
                                            </td>
		</tr><tr class="pgr" align="center">
			<td colspan="6"><table border="0">
				<tr>
					<td><span>1</span></td><td><a href="javascript:__doPostBack('gvClients','Page$2')">2</a></td><td><a href="javascript:__doPostBack('gvClients','Page$3')">3</a></td><td><a href="javascript:__doPostBack('gvClients','Page$4')">4</a></td><td><a href="javascript:__doPostBack('gvClients','Page$5')">5</a></td><td><a href="javascript:__doPostBack('gvClients','Page$6')">6</a></td><td><a href="javascript:__doPostBack('gvClients','Page$7')">7</a></td><td><a href="javascript:__doPostBack('gvClients','Page$8')">8</a></td><td><a href="javascript:__doPostBack('gvClients','Page$9')">9</a></td><td><a href="javascript:__doPostBack('gvClients','Page$10')">10</a></td><td><a href="javascript:__doPostBack('gvClients','Page$11')">...</a></td><td><a href="javascript:__doPostBack('gvClients','Page$Last')">Last</a></td>

				</tr>
			</table></td>
		</tr>
	</table>
 
Ahh, yes I see.

Just so I'm clear each of your checkboxes has a related textboxyou want to disable if the checkbox is unchecked correct?

You'd want to start by setting all your textboxes to being disabled to being with. Following that, use the checkbox that was activated to construct the ID of the corresponding textbox since they appear to have the same base (gvClients_ct119, gvClients_ctl20, gvClients_ctl21 ...), with only the "CheckBoxActiveClient" or "Copies" part being different. With the Id constructed you can then find the textbox and enable or disable it accordingly. You are already sending the clicked-on checkbox to your function so its easy from there.

Code:
function TogleCopies(CheckBox){
var IdBase=CheckBox.id;
var idParts=IdBase.split('-');
var TextBoxId=idParts[0] + '-' + idParts[1] + "-Copies";
var textBox=document.getElementById(TextBoxId);

if(CheckBox.checked){
textBox.disabled=true;
}

else{
textBox.disabled=false;
}

}


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Phil AKA Vacunita, I tried your code in the javascript function, but nothing happens when I check/uncheck the checkbox.
Thanks,
 
Ahh, sorry, I split along dashes rather than underscores.


Code:
function TogleCopies(CheckBox){
var IdBase=CheckBox.id;
var idParts=IdBase.split('[red]_[/red]');
var TextBoxId=idParts[0] + '[red]_[/red]' + idParts[1] + "[red]_[/red]Copies";
var textBox=document.getElementById(TextBoxId);

if(CheckBox.checked){
textBox.disabled=true;
}

else{
textBox.disabled=false;
}

}


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top