1

Hi i have two tables in a form it need to validate them individually in jquery.When i click on submit1 it should validate only table1, when i click on submit2 it should validate only table 2.

right now it validating both at same time i need individual table validations

<html>
<head>
    <script type="text/javascript">

        $(document).ready(function() {

            $("#form1").validate({

                rules: {

                    <%= txtUserName.UniqueID %>: {minlength: 5, required: true},    

                    <%= txtPassword.UniqueID %>: {minlength: 5, required: true},

                    <%= txtURL.UniqueID %>: {required: true},
                 }, 

                messages: {

                    <%= txtUserName.UniqueID %>: {

                        required: "Plaese enter your name",    

                        minlength: "User name must be atleaet of 5 characters"
                    },

                    <%= txtPassword.UniqueID %>: { 

                        required: "Plaese enter your password",     

                        minlength: "Password must be atleaet of 5 characters"    
                    },

                    <%= txtURL.UniqueID %>:{ required: "Plaese enter Website URL",},
                }

            });

        });    
    </script>
</head>    
<body>    
    <form id="form1" runat="server">

        <table width="50%" cellpadding="2" cellspacing="4" style="border: solid 1px navy; background-color: #d5d5d5;">

---username--
--password--
--url----
submit1
        </table>


 <table width="50%" cellpadding="2" cellspacing="4" style="border: solid 1px navy; background-color: #d5d5d5;">

---Firstname--
--Lastname--

-Address----
submit2

        </table>    
    </form>
</body>
nnnnnn
  • 147,572
  • 30
  • 200
  • 241
Phanindra Kumar
  • 171
  • 3
  • 16

1 Answers1

1

Using CSS classes as flags is a great way to emulate that concept in plain (X)HTML markup. Especially when using jQuery, CSS “flags” are a great way to tag elements with arbitrary attributes, that are easy to find with simple DOM selectors later.

Fieldsets with a validationGroup class, we end up with this markup:

<fieldset class="validationGroup">
  <legend>Returning customer?  Login here</legend>
 
  <!-- Username and Password labels and inputs here -->
</fieldset>

Follow this for complete implementation:Emulate ASP.NET validation groups with jQuery validation

Reference links:
jQuery validation: Indicate that at least one element in a group is required

jQuery Validate - require at least one field in a group to be filled

Community
  • 1
  • 1
Niranjan Singh
  • 18,017
  • 2
  • 42
  • 75