Click here to Skip to main content
15,914,419 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Professionals,
Am validating controls which is empty by using Jquery, and below is my JQUERY and how am calling in that into my textboxes, it work fine, but my need is, I need to check this validation based up on controls in div, hope you guys understand, kindly help me

Below is my JQUERY
ASP.NET
<link href="ValidationEngine.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .auto-style1 {
            width: 611px;
        }
    </style>
    <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 type="text/javascript">
    $(function () {
        $("#form1").validationEngine('attach', { promptPosition: "topRight" });
    });
    function DateFormat(field, rules, i, options) {
        var regex = /^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/;
        if (!regex.test(field.val())) {
            return "Please enter date in dd/MM/yyyy format."
        }
    }
</script>

Below line is where i called the above JQUERY

<input type="text" class="validate[required]"  runat="server" name="pgUsername" id="txtusername"  >
Posted
Updated 19-Jun-14 20:55pm
v2
Comments
VICK 20-Jun-14 5:38am    
""validation based up on controls in div""

Can you explain this a bit further.

As you are using JQUERY Validation Plugin. so consult their website. or explain the problem here a bit more.
peer mohammed.A 20-Jun-14 7:04am    
actually i have two div in same page, first one is below div
<div class="login_section">
<table width="100%" cellpadding="">
<tr>
<td> Username <span class="star">*</span>
<%--<input type="text" runat="server" id="txtname" name="txtname1" class="validate[required]" ></td>--%><%--input_box2--%>
<input type="text" class="validate[required]" runat="server" name="pgUsername" id="txtusername" ></td><%--input_box2--%>
<td> Password <span class="star">*</span>
<%--<input type="text" runat="server" id="txtpass" name="txtpass1" class="validate[required]" >--%>
<input type="text" runat="server" id="txtpassword" class="validate[required]" name="pgPassword" >
</td>
</tr>
<tr>
<td>
<input type="submit" class="sub_btn" id="btnlogin" önserverclick="fnhome_page" runat="server" value="Login">

Forgetpassword</td>
<td></td>
</tr>
</table>
</div>

And below is the second one

<div class="Register_section">
<table width="100%" cellpadding="">
<tr>
<td> Username <span class="star">*</span>
<%--<input type="text" class="input_box2" >--%>
<input type="text" runat="server" name="reguser" id="txtreguser" ><%--class="validate[required]"--%>
</td>
<td> Email <span class="star">*</span>
<%--<input type="text" class="input_box2" >--%>
<input type="text" runat="server" name="regemail" id="txtregemail" ><%--class="validate[required]"--%>
</td>
</tr>
<tr>
<td> Password <span class="star">*</span>
<%--<input type="text" class="input_box2" >--%>
<input type="text" runat="server" name="regpassword" id="txtregpass" > <%--class="validate[required]"--%>
</td>
<td> Re-enter Password <span class="star">*</span>
<%--<input type="text" class="input_box2" >--%>
<input type="text" runat="server" name="regconfpassword" id="txtregconfpass"><%--class="validate[required]"--%>
</td>
</tr>
<tr>
<td ><input type="submit" runat="server" önserverclick="fnregisteruser" class="sub_btn" value="Register">
</td>
<td></td>
</tr>
</table>
</div>


Now i come to my points, each div contain certain textboxes with button
My requirement is if am clicking the button of first div means it should check only that div textboxes are empty, no need to check another div, but as per my above coding validate all textboxes of 1st & 2nd div.

I think u got my point.

1 solution

In jquery you just page the container and using find check validate class.

$( "Container" ).each(function() {
{
var invalid = false;
var txt = $(this).find('yourclass ').val()
if (txt.length == 0)
{
invalid= true;
}

}

Based on that you can validate all controls.
 
Share this answer
 
v2
Comments
peer mohammed.A 20-Jun-14 5:30am    
Can you explain how to call this jquery in which control we want to check ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900