Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

1. i have a grid view with template fields with 2 checkbox column and a textbox column.
i need javascript to toggle the check status in the checkboxes(i.e i hav 2 checkbox with name chkapprove and chkreject, if i check "chkapprove" then "chkreject" should uncheck if it is already checked and vice versa)
2. i need a button click function which has to alert with msg "Enter the reason" when chkreject is checked and nothing is entered in the text box..

JavaScript
function reason() 
    {

        MyGridView = document.getElementById('<%= grdaccess.ClientID %>');
        var Inputs = MyGridView.getElementsByTagName("input");
        var chkBox = "Chkreject";
        var textbox = "txtreason";
        for (var n = 0; n < Inputs.length; ++n)
            if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(chkBox, 0) >= 0 && Inputs[n].checked)
                if (Inputs[n+1].type == 'textbox' && Inputs[n+1].id.indexOf(textbox, 0) >= 0 && Inputs[n+1].length <= 0)
                 {
                    alert("enter the reason");
                    return false;
                }
                return true;
    }

ASP.NET
<asp:Button ID="btnSubmit" runat="server" CssClass="showall" Text="Submit"  OnClientClick="javascript:return reason();" onclick="btnsubmit_Click" />

this is the code i have written for condition 2 . but its not working.

this is my html code:


can someone help me with this ?

C#
<asp:GridView ID="grdaccess" runat="server" CssClass="mGridv"  AutoGenerateColumns="False"
                                                        
                                                                                          
                                                        AllowPaging="True"  CellPadding="4"
                                                        BackColor="White"  PagerSettings-PageButtonCount="5" PagerSettings-Mode= "NumericFirstLast"
                                                        BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" 
                                                        GridLines="Horizontal" EnableViewState="false"
                                                            onrowdatabound="grdaccess_RowDataBound" onpageindexchanging="grdaccess_PageIndexChanging" 
                                                         >

                                                       <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
                                                <HeaderStyle CssClass="first"  Font-Bold="true" />
                                                        <PagerStyle  CssClass="pgr" ></PagerStyle>

                                                        <RowStyle CssClass="odd"  />
                                                        <AlternatingRowStyle CssClass="even" BackColor ="White"   />
                                                        <Columns>
                                                             <asp:TemplateField HeaderText="Case Study Name">
                                                                <ItemTemplate>
                                                                    
                                                                     <asp:LinkButton ID ="lbcsname" runat ="server" OnClick="lnkCustomer_Click" ></asp:LinkButton>
                                                                </ItemTemplate>
                    
                                                              
                                                            </asp:TemplateField>

                                                              
                                                           
                                                            <asp:TemplateField  HeaderText="Esa Project">
                                                                <ItemTemplate>
                                                                    <asp:Label ID="lblprojects" runat="server"></asp:Label>
                                                                </ItemTemplate>
                                                                 
                                                              </asp:TemplateField>
                                                               <asp:TemplateField  HeaderText="WorkFlow">

                                                               <ItemTemplate>
                                                                    <asp:LinkButton runat="server" ID="lnkworkflowhistory" 
                                       
                                                                                    OnClick="lnkworkflow_click">
                                                                    </asp:LinkButton>
                                                                    </ItemTemplate>


                                                                
                                                                 
                                                              </asp:TemplateField>
                                                             
                                                              <asp:TemplateField HeaderText="DeliveryManager">
                                                                <ItemTemplate>
                                                                    <asp:Label ID="lbldeliverymanager" CssClass="leftalign" runat="server"></asp:Label>
                                                                </ItemTemplate>
                                                                 
                                                              </asp:TemplateField>
                                                               <asp:TemplateField  HeaderText="Client">
                                                                <ItemTemplate>
                                                                    <asp:Label ID="lblclient" CssClass="leftalign" runat="server"></asp:Label>
                                                                </ItemTemplate>
                                                                 
                                                              </asp:TemplateField>
                                                             
                                                                <asp:TemplateField  HeaderText="Status" Visible="false">
                                                                <ItemTemplate>
                                                                    <asp:Label ID ="lbstatus" runat ="server"  ></asp:Label>
                                                                </ItemTemplate>
                                                                 
                                                              </asp:TemplateField>

                                                               <asp:TemplateField  HeaderText="Approve" ItemStyle-HorizontalAlign="Center" >
                                                                <ItemTemplate>
                                                                    <asp:CheckBox ID="Chkapprove" runat="server"    AutoPostBack="true" />
                                                                </ItemTemplate>
                                                                 
                                                              </asp:TemplateField>    
                                                              <asp:TemplateField  HeaderText="Reject"  ItemStyle-HorizontalAlign="Center">
                                                                <ItemTemplate>
                                                                    <asp:CheckBox  ID="Chkreject"  runat="server"   AutoPostBack="true" />
                                                                    
                                                                </ItemTemplate>
                                                                 
                                                              </asp:TemplateField>     
                                                              <asp:TemplateField  HeaderText="Remarks">
                                                                <ItemTemplate>
                                                              <asp:TextBox ID="txtreason" runat="server"></asp:TextBox>
                                                              </ItemTemplate>
                                                              </asp:TemplateField>                                 
                                                                                                                   
                                                        </Columns>
                                                        <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
                                                        <SortedAscendingCellStyle BackColor="#F4F4FD" />
                                                        <SortedAscendingHeaderStyle BackColor="#5A4C9D" />
                                                        <SortedDescendingCellStyle BackColor="#D8D8F0" />
                                                        <SortedDescendingHeaderStyle BackColor="#3E3277" />
                                                    </asp:GridView>                                                                                   


                                  
                                                                                        <asp:Button ID="btnSubmit" runat="server" CssClass="showall" Text="Submit"  OnClientClick="javascript:return reason();"                                                         onclick="btnsubmit_Click" />


thanks in advance ,
gowrishankar
Posted
Updated 31-Jan-12 20:59pm
v5
Comments
Christian Graus 1-Feb-12 1:18am    
You should also let us see the HTML that gets sent to the client, to make sure it's rendering in the way you want it to. What happens when you step through the javascript, or put alerts in to tell you what is called ?
gowrishankar s 1-Feb-12 1:52am    
i have added the html code.. thanks,gowrishankar.

1 solution

Try to use Inputs[n+1].type == 'text'
 
Share this answer
 

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