ASP.Net JQuery customvalidator on multiple fields

tiarty

New Member
I am trying to do validation on multiple fields with the custom validator in ASP.net using JQuery but I can't get it to work.There is a drop down box which contains two values, based on these values other items appear.So if the user selects option 1, then a text box appears, if they select option 2 the text box disappears and two drop down boxes appear.Depending on what option they choose I want to validate their input.What I have so far that is not working is.ASPX\[code\]<asp:DropDownList ID="drpHeight" runat="server"> <asp:ListItem Value="http://stackoverflow.com/questions/15522551/CMs">CMs</asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15522551/Feet">Feet</asp:ListItem> </asp:DropDownList><asp:TextBox ID="txtCm" runat="server" Width="100px"></asp:TextBox> <asp:CustomValidator ID="CustomValidator9" runat="server" ErrorMessage="Please select you height" ClientValidationFunction = "ValidateHeight" Display="Dynamic" ControlToValidate="txtCm" ValidateEmptyText="true"></asp:CustomValidator> <asp:RegularExpressionValidator ID="revCm" runat="server" ControlToValidate="txtCm" Display="Dynamic" ErrorMessage="Please enter a valid number" ValidationExpression="^([0-9]*|\d*\.\d{1}?\d*)$" SetFocusOnError="True"></asp:RegularExpressionValidator><br /><br /><asp:DropDownList ID="drpFeet" runat="server"> <asp:ListItem Value="http://stackoverflow.com/questions/15522551/-1">Select...</asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15522551/1"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15522551/2"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15522551/3"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15522551/4"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15522551/5"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15522551/6"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15522551/7"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15522551/8"></asp:ListItem> </asp:DropDownList> <asp:Label ID="lblFeet" runat="server" Text="Ft"></asp:Label> &nbsp;<asp:DropDownList ID="drpInches" runat="server"> <asp:ListItem Value="http://stackoverflow.com/questions/15522551/-1">Select...</asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15522551/0"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15522551/1"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15522551/2"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15522551/3"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15522551/4"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15522551/5"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15522551/6"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15522551/7"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15522551/8"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15522551/9"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15522551/10"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15522551/11"></asp:ListItem> </asp:DropDownList> &nbsp;<asp:Label ID="lblInches" runat="server" Text="Inches"></asp:Label> <br /><br />\[/code\]JQuery \[code\] function ValidateHeight(sender, args) { if ($('#<%=drpHeight.ClientID%>').val = "CMs") { if ($('#<%=txtCm.ClientID%>').val().length > 0) { args.IsValid = true; } else { args.IsValid = false; return; } } else if ($('#<%=drpHeight.ClientID%>').val = "Feet") { args.IsValid = true; } } </script>\[/code\]At the moment it is not working, I did have it validating the CM b but then it stopped working and now I can't figure out why. What is the best way to approach this? I've got another one for Weight to do as well, that one has 3 input possibilities.
 
Back
Top