Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends ,

I have a ajax calendar extender and the textbox where the selected date is shown , initially when the date was change I was rasising a javascript to change the Text forecolor , so that user can know which dates he/she has change

but the new requirement is to use the checkbox

can anyone please assist to tell me , how can I achieve a checkbox check when textbox box value is change

below is the code for example

Grdiview example sample item column where I am calling javascript


ASP.NET
<ItemTemplate>
                                                            <asp:Label ID="lblProjectStartDate" runat="server" Text='<%# Bind("StartDate") %>'
                                                                Visible="false"></asp:Label>
                                                                <asp:CheckBox ID="chkProjectStartDate"  Enabled="true"  runat="server" Checked='<%# (((bool)(Eval("IsProjectDate"))) ? (bool)false: (bool)true ) %>' />
                                                            <asp:TextBox ID="txPrjStartDate" runat="server" contentEditable="false" BorderStyle="None"
                                                                CssClass="tm-text" Text='<%# Bind("StartDate") %>' Visible="true" Width="82px"
                                                                onchange="txtChange('<%= chkProjectStartDate.ClientID%>');"></asp:TextBox>
                                                            <asp:ImageButton ID="imgProjectStartDate" runat="server" Height="20px" ImageUrl="~/Images/Shared/icon_calendar.jpg"
                                                                Width="20px" />
                                                            <asp:CalendarExtender ID="calPrjStartDate" runat="server" Enabled="True" Format="dd/MM/yyyy"
                                                                PopupButtonID="imgProjectStartDate" TargetControlID="txPrjStartDate">
                                                            </asp:CalendarExtender>
                                                            <asp:RequiredFieldValidator ID="rfSTDate" runat="server" ControlToValidate="txPrjStartDate"
                                                                CssClass="mandatory" Display="Dynamic" ErrorMessage="required" ValidationGroup="SavePS"></asp:RequiredFieldValidator>
                                                        </ItemTemplate>



JavaScript code

XML
<script type="text/javascript">
              function txtChange(chkCheckbox) {
                  chkCheckbox.checked = true;

              }
          </script>
Posted
Updated 2-Feb-14 17:26pm
v2

1 solution

Try this

HTML
<script type="text/javascript">
      function txtChange(chkCheckbox) {
          var td = chkCheckbox.offsetParent;
          var inputs = td.getElementsByTagName("input");
          for (var i = 0; i < inputs.length; i++) {
              if (inputs[i].type == 'checkbox') {
                  inputs[i].checked = true;
                  break;
              }
          }
      }
  </script>



HTML
onchange="txtChange(this);
 
Share this answer
 
Comments
Rickin Kane 2-Feb-14 23:48pm    
Karthik , worked like a charmed , thanks a lot , was struggling since morning Many thanks and have a great week ahead
Karthik_Mahalingam 3-Feb-14 1:21am    
welcome Rickin Kane :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900