troubleshooting Question

user validation on drop down box and input box

Avatar of dipster307
dipster307 asked on
JavaScript.NET ProgrammingASP.NET
1 Comment1 Solution245 ViewsLast Modified:
I am trying to create a user validation on a drop down and input box. Basically I have a input box which must have data entered if the drop down is selected on value "No".

I am using asp.net in c#, and javascript.

               <asp:DropDownList CssClass="DropdownListStyle" ID="drpDetails" runat="server">
               <asp:ListItem Value=""></asp:ListItem>
               <asp:ListItem Value="Yes">Yes</asp:ListItem>
               <asp:ListItem Value="No">No</asp:ListItem>
               </asp:DropDownList>

               <asp:TextBox ID="txtNoDataSources" runat="server"></asp:TextBox>

               <asp:CustomValidator ID="CVNoDataSources"
               ControlToValidate="txtNoDataSources"
               ClientValidationFunction="CVDropDown"
               ValidationGroup="VGPageSummary" Text="Must enter value" runat="server">
               </asp:CustomValidator>


    <script type="text/javascript">
        function CVDropDown(sender, args) {
            var drpObj = document.getElementById('drpPayrollDetails').value;
            alert(drpObj);
            alert(args.Value);
            if ((drpObj == "No") && (args.Value == "")) {
                args.IsValid = false;
            }
        }
    </script>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 1 Comment.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros