I have two textboxes in my asp.net application. I want to make txtContact a mandatory field if user enters something in txtName using JavaScript.
Here is my code,
<asp:TextBox ID="txtName" runat="server" CssClass="selectstyle" onkeypress="javascript:AvoidEnter();" MaxLength="10" ValidationGroup="CreateUser" />
<asp:TextBox ID="txtContact" runat="server" CssClass="selectstyle" onkeypress="javascript:AvoidEnter();" MaxLength="20" />
<asp:RequiredFieldValidator ErrorMessage="Please enter contact info" ClientIDMode="Static" ID="rfvContact" Enabled="false" ValidationGroup="CreateUser" ControlToValidate="txtContact" runat="server" />
<script type="text/javascript">
$(function () {
$('#<%= txtName.ClientID %>').blur(function () {
if ($.trim($('#<%= txtName.ClientID %>').val()) != '') {
//enable container number validator
ValidatorEnable(document.getElementById('<%=rfvContact.ClientID%>'), true);
}
else {
//disable container number validator
ValidatorEnable(document.getElementById('<%=rfvContact.ClientID%>'), false);
}
});
});
</script>
The problem with above script is, it is working completely fine in Chrome browser but the validation is not working in IE 11.
Any other alternative please?