In a webpage, there are multiple validators and a dropdown. In the dropdown, if the option selected is Y, all validators should fire. If option selected is N, then all validators should be disabled. The server-side code is simple. How can this be done in javascript?

The HTML of the page looks like this:


 <asp:DropDownList ID="ddlList" runat="server" OnChange="ValidateIf();">
    <asp:ListItem Value="Y" Text="Yes"></asp:ListItem>
    <asp:ListItem Value="N" Text="No"></asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="val" runat="server" ControlToValidate="txtName"
                             ValidationGroup="Group1" Display="Dynamic"  
                             ErrorMessage="Please enter name" 
                             >
</asp:RequiredFieldValidator>
<asp:Button ID="btn" runat="server" Text="Submit" ValidationGroup="Group1" CausesValidation="true" />

When the dropdown is changed, then the javascript function - ValidateIf() is fired. This contains logic to enable / disable the validators. The function ValidatorEnable() is used for each validator


 function ValidateIf() {
    var list = document.getElementById('ddlList');
    var val = document.getElementById('val');
    
    if (list.options[list.selectedIndex].value == "Y") {
        ValidatorEnable(val, true);        
    }
    else {
        ValidatorEnable(val, false);
    }
}