I am trying to validate a textbox based on a dropdownlist, e.g. if ddl value is ‘Day’, textbox value cannot exceed 31. It seems that no matter what I enter triggers my custom validator error, what am I doing wrong, thanks:
<asp:TextBox ID="uitxtCamLastVisitDur" runat="server" CssClass="tooltip"
Width="65px" Enabled="False" ToolTip="Indicates a required spending on the member's last visit."></asp:TextBox>
<asp:CustomValidator ID="ccvLastVisitDuration" runat="server"
ClientValidationFunction="validateDurationType"
ControlToValidate="uitxtCamLastVisitDur"
ErrorMessage="Duration input error"></asp:CustomValidator>
function validateDurationType(src, args) {
if (document.getElementById('<%= uiddlCamLastVisitDurType.ClientID%>').selectedIndex == 1)
if (parseInt(document.getElementById('<%= uitxtCamLastVisitDur.ClientID%>').value < 0) || (parseInt(document.getElementById('<%= uitxtCamLastVisitDur.ClientID%>').value > 31))) {
args.IsValid = false;
return;
}
if (document.getElementById('<%= uiddlCamLastVisitDurType.ClientID%>').selectedIndex == 2)
if (parseInt(document.getElementById('<%= uitxtCamLastVisitDur.ClientID%>').value < 0) || (parseInt(document.getElementById('<%= uitxtCamLastVisitDur.ClientID%>').value > 12))) {
args.IsValid = false;
return;
}
args.IsValid = true;
}
You have javascript errors on your function. You are missing parenthesis on parseInt:
Should be
All of them have the same issue, by the way.