Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have one text box.

Name textbox

Validate the above textbox using Jquery.


for that download the jquery 1.4.1 and put in that project script.

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">
</head>


<body>
<form id="form1" runat="server">



<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript">
<script src="Scripts/jquery.validate.js" type="text/javascript"></script>

<script type ="text/javascript" > 
                    
        $(document).ready(function () {  
            $("#form1").validate({ 
             
                rules: {  
                    <%=txtName.UniqueID %>:{  
                        required:true  
                    }, 
                    
                 }  


                },  

                messages: {  
                     
                      <%=txtName.UniqueID %>:{  
                          required: "Name should not be empty"  
                      }, 



                                  }

            });  
        });         
  </script>
    

    


    <style type ="text/css" >  
        label.error {             
            color: red;   
            display:inline;                 
        }  
        .error
        {
            height: 26px;
        }
    </style>    

    <br />  
   
    Name <asp:TextBox ID="txtName" runat="server">  
    <br />  
    <br /> 

  <asp:Button ID="btnSubmit" runat="server" Text="Submit" CssClass="error" 
            onclick="btnSubmit_Click" />   

</form>
</body>
</html>


i have one text box validate that textbox using jquery.

When i run as follows

Name textbox

Without typing in text box and click submit message not shown.

what is the mistake in my above code.

What I have tried:

validate the textbox using JQuery
Posted
Updated 12-Jun-16 1:55am
Comments
Karthik_Mahalingam 12-Jun-16 3:29am    
There is not code related to what you have mentioned. post the relevant code.
what type of validation ?

1 solution

Try This
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server"> 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.js" type="text/javascript">  </script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.15.0/jquery.validate.js" type="text/javascript"></script>
        <script type="text/javascript"> 
            $(document).ready(function () { 
                $("#form1").validate({ 
                    rules: { 
                        <%=txtName.UniqueID %>:{ 
                            required:true 
                        }
                    }, 
                    messages: { 

                        <%=txtName.UniqueID %>:{ 
                            required: "Name should not be empty" 
                        } 
                }
                }); 
            }); 
        </script>
        <style type="text/css">
            label.error {
                color: red;
                display: inline;
            }

            .error {
                height: 26px;
            }
        </style>
</head>
<body>
    <form id="form1" runat="server">
        
                Name<asp:textbox id="txtName" runat="server" xmlns:asp="#unknown"></asp:textbox>
<asp:button id="btnSubmit" runat="server" text="Submit" cssclass="error" onclick="btnSubmit_Click" xmlns:asp="#unknown" />
    </form>
</body>
</html></html>
 
Share this answer
 

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