locked
Validation of combo box RRS feed

  • Question

  • User582566331 posted

    Required field validation using jquery is not working for combo box. I am using rference to validation engine.

    <asp:ComboBox ID="cbBillTitle" runat="server"
                                            CaseSensitive="false"  cssClass="validate[required]"
                                              AutoPostBack="true">
                                               
                                               <asp:ListItem tEXT="SELECT" Value=" "></asp:ListItem>
                                                  <asp:ListItem tEXT="mR" Value="MR"></asp:ListItem>
                                                     <asp:ListItem tEXT="mRS" Value="MRS"></asp:ListItem>
                                               
                                        </asp:ComboBox>
                                        
                                        
                                        <asp:Button ID="btnSubmit" runat="server" />

    Monday, April 11, 2016 11:36 AM

Answers

  • User61956409 posted

    Hi sweetyPaul,

    Required field validation using jquery is not working for combo box. I am using rference to validation engine.

    It seems that you are using jQuery Validation Engine Plugin to validate form, and it does not work fine with ComboBox control. You could refer to the following working sample to modify your code.

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <link href="ValidationEngine.css" rel="stylesheet" type="text/css" />
    
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    
        <script type="text/javascript" src="http://cdn.ucb.org.br/Scripts/formValidator/js/languages/jquery.validationEngine-en.js"
            charset="utf-8"></script>
    
        <script type="text/javascript" src="http://cdn.ucb.org.br/Scripts/formValidator/js/jquery.validationEngine.js"
            charset="utf-8"></script>
    
        <script>
            $(function () {
                $("#cbBillTitle").find(":text").addClass("validate[required]");
    
                $("#form1").validationEngine();
            })
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
            <div>
                <asp:TextBox ID="TextBox1" runat="server" CssClass="validate[required]"></asp:TextBox>
                <br />
                <asp:ComboBox ID="cbBillTitle" runat="server" CaseSensitive="false" AutoPostBack="true">
                    <asp:ListItem Text="SELECT" Value=" "></asp:ListItem>
                    <asp:ListItem Text="mR" Value="MR"></asp:ListItem>
                    <asp:ListItem Text="mRS" Value="MRS"></asp:ListItem>
                </asp:ComboBox>
                <br />
                <asp:Button ID="Button1" runat="server" Text="Button" />
            </div>
        </form>
    </body>
    </html>
    

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 12, 2016 4:16 AM

All replies

  • User-359936451 posted

    Since you have auto Postback set to true, are you over writing the change with the post back?

    In you load event add code to test for post back

    If not ispostback then

       ' test

    else

       'test something else

    end if

    Monday, April 11, 2016 3:11 PM
  • User61956409 posted

    Hi sweetyPaul,

    Required field validation using jquery is not working for combo box. I am using rference to validation engine.

    It seems that you are using jQuery Validation Engine Plugin to validate form, and it does not work fine with ComboBox control. You could refer to the following working sample to modify your code.

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <link href="ValidationEngine.css" rel="stylesheet" type="text/css" />
    
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    
        <script type="text/javascript" src="http://cdn.ucb.org.br/Scripts/formValidator/js/languages/jquery.validationEngine-en.js"
            charset="utf-8"></script>
    
        <script type="text/javascript" src="http://cdn.ucb.org.br/Scripts/formValidator/js/jquery.validationEngine.js"
            charset="utf-8"></script>
    
        <script>
            $(function () {
                $("#cbBillTitle").find(":text").addClass("validate[required]");
    
                $("#form1").validationEngine();
            })
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
            <div>
                <asp:TextBox ID="TextBox1" runat="server" CssClass="validate[required]"></asp:TextBox>
                <br />
                <asp:ComboBox ID="cbBillTitle" runat="server" CaseSensitive="false" AutoPostBack="true">
                    <asp:ListItem Text="SELECT" Value=" "></asp:ListItem>
                    <asp:ListItem Text="mR" Value="MR"></asp:ListItem>
                    <asp:ListItem Text="mRS" Value="MRS"></asp:ListItem>
                </asp:ComboBox>
                <br />
                <asp:Button ID="Button1" runat="server" Text="Button" />
            </div>
        </form>
    </body>
    </html>
    

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 12, 2016 4:16 AM