How can I get the parent in the asp:CustomValidator javascript function
How can I get the parent in the asp:CustomValidator javascript function so that I can used it to check whether the related checkbox have been checked?
Example:
I have the following code:
<tr>
<th class="graytext r">Add Reps to Team:</th>
开发者_StackOverflow社区 <td>
<asp:GridView ID="grid" runat="server" AutoGenerateColumns="False" DataKeyNames="EmployeeID"
DataSourceID="dsEmployees" EnableViewState="false"
GridLines="None" CssClass="clGridDirectory">
<Columns>
<asp:TemplateField >
<ItemTemplate>
<asp:CheckBox runat="server" ID="employee_name" CssClass="employee_name" Text='<%# Eval("fullname") %>'/>
<asp:HiddenField runat="server" ID="employeeidToRep" Value='<%# Eval("employeeid") %>'/>
<asp:TextBox runat="server" ID="repID" Text='<%# Eval("rep_id") %>' />
<asp:CustomValidator id="CustomValidator2" runat="server"
ControlToValidate = "repID"
ErrorMessage = ""
ClientValidationFunction="test" >
</asp:CustomValidator>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="dsEmployees" runat="server" ConnectionString="<%$ ConnectionStrings:TestConnectionString %>"
SelectCommand="app_staff_without_team_select" SelectCommandType="StoredProcedure">
</asp:SqlDataSource>
</td>
</tr>
Jquery code:
function test(oSrc, args) {
var $tb = $('input[id$=employee_name]');
// only validate if an <asp:Checkbox> called chkOtherCheckbox is ticked
alert(args.Value.toString())
if ($('input:checkbox[id$=chkOtherCheckbox]').is(':checked'))
alert('checked')
else
alert('no checked')
}
How can I get the parent in the test function so that I can used it to check whether the related checkbox have been checked?
You can use this code for getting the state of nearest checkbox.
function test(oSrc, args) {
var nearestCheckBox= $(oSrc).parent().find('input:checkbox:first');
var state=nearestCheckBox.attr('checked');//use this variable
}
精彩评论