Reputation: 83
i want to active / disable required field on dropdownlist , if radiobutton1 checked requiredvalidator active else remain disable.
html code
<asp:RadioButton runat="server" id="radioA1" GroupName="overseas" />
<label for="radioA1">Yes </label>
<asp:RadioButton runat="server" id="radioA2" GroupName="overseas" />
<label for="radioA2">No</label>
<asp:RadioButton runat="server" id="radioA3" GroupName="overseas" />
<label for="radioA2">Not Applicable</label>
<br />
Overseas Country
<asp:DropDownList ID="DropDownList10" AppendDataBoundItems="True" CssClass="form-control mySelecBox" runat="server" DataSourceID="newCountry" DataTextField="Country" DataValueField="CountryGuid">
<asp:ListItem Text="" Value="" />
</asp:DropDownList>
<asp:SqlDataSource ID="newCountry" runat="server" ConnectionString="<%$ ConnectionStrings:umtonlineConnectionString %>" SelectCommand="SELECT [CountryGuid], [Country] FROM [countries]"></asp:SqlDataSource>
<asp:RequiredFieldValidator ID="RequiredFieldValidator13" runat="server" ControlToValidate="DropDownList10" Enabled="False" ErrorMessage="Oversea country required *" ForeColor="#CC0000" ValidationGroup="step1"></asp:RequiredFieldValidator>
<br />
Jquery code:
$(document).ready(function () {
$('#<%=radioA1.ClientID%>').click(function () {
alert("its working"); // this part work fine.
ValidatorEnable($('#<%=RequiredFieldValidator13%>'));
});
});
Upvotes: 0
Views: 143
Reputation: 56716
First, that should obviously be calling ClientID:
'#<%=RequiredFieldValidator13.ClientID%>'
Second, ValidatorEnable expects a dom object, not a jQuery one. So
var validator = document.getElementById('<%=RequiredFieldValidator13.ClientID%>');
or, as suggested by kman in the comments:
var validator = $('#<%=RequiredFieldValidator13.ClientID%>')[0];
Third, it also expects a second parameter, boolean specifying whether to enable or disable the validator. I guess this should be set according to the dropdownlist value.
Upvotes: 1