Hi,
I have a dropdown list, where when I select OPTION value a Textbox appears. The issue is that when, I submit directly the required filed errors gives me message for both ie for dropdown and Textbox. It should only give error for dropdown.
Second thing,
The textbox validation is not firing when submitted without any value in it.
Please see the code for your reference:
<asp:DropDownList ID="ddlGraduation" runat="server" CssClass="txtfld-popup_drp1">
</asp:DropDownList>
<asp:RequiredFieldValidator CssClass="error_msg" ID="reqGraduation" runat="server" ControlToValidate="ddlGraduation" ErrorMessage="Please select graduation details" InitialValue="--Select--" SetFocusOnError="true"></asp:RequiredFieldValidator>
<asp:TextBox ID="txtOther" runat="server" CssClass="txtfld-popup_p1"></asp:TextBox>
<asp:RequiredFieldValidator ID="reqOther" runat="server" ControlToValidate="txtOther" SetFocusOnError="true" ErrorMessage="Please specify other qualification"></asp:RequiredFieldValidator>
javascript for handling the validation:-
<script type="text/javascript">
$('#ctl00_ContentPlaceHolder1_txtOther').hide();
$('#ctl00_ContentPlaceHolder1_ddlGraduation').change(function () {
if ($(this).val() === "Other") {
$('#ctl00_ContentPlaceHolder1_txtOther').show();
//Enable the validator when textbox is shown
ValidatorEnable(document.getElementById("<%=reqOther.ClientID %>"), true);
return false;
}
else {
$('#ctl00_ContentPlaceHolder1_txtOther').hide();
//Disable the validator when textbox is hidden
ValidatorEnable(document.getElementById("<%=reqOther.ClientID %>"), false);
return true;
}
});
</script>