Help On jquery validations

Posted by Vijayar under jQuery on 12/1/2011 | Points: 10 | Views : 1133 | Status : [Member] | Replies : 1
Hi
I am using jquery validations for required fields in asp.net page.But the validations are not getting fired.
<script type="text/javascript">
$(document).ready(function() {
$("#frmnote").validate({
rules:
{
'<%= txtnote.UniqueID %>' :
{
required: true,
minlength: 2

}
},
messages:
{
'<%=txtnote.UniqueID %>':
{
required: "* Required Field *",
minlength: "* Please enter atleast 2 characters *"
}
}
});
});
</script>
<form id="frmnote" method="get" action="">
<div>
<div>
<table style="width: 100%">
<tr>
<td style="width: 100%" align="center">
<table>
<tr>
<td align="left" style="width:200px">
<asp:Label ID="Label1" runat="server" Text="Note Name"></asp:Label><span style="color: Red">*</span>
</td>
<td align="left">
<asp:TextBox ID="txtnote" runat="server" CssClass="txtbox" MaxLength="20"
AutoCompleteType="Disabled"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ForeColor="Red" runat="server" ErrorMessage="Enter Note Name!"
ControlToValidate="txtnote" Display="Dynamic" CssClass="validationstyle"></asp:RequiredFieldValidator>
</td>
</tr>
</table>
</form>
iam using jquery plug-ins also.Please help me in this issue.What is my mistake

vijaya


Responses

Posted by: Hemanthlaxmi on: 12/1/2011 [Member] Starter | Points: 25

Up
0
Down
You can checkout the rules add function(http://docs.jquery.com/Plugins/Validation/rules#.22add.22rules) , but basically here's what you can do:

jQuery(function() {
// You can specify some validation options here but not rules and messages
jQuery('form').validate();
// Add a custom class to your name mangled input and add rules like this
jQuery('.username').rules('add', {
required: true,
messages: {
required: 'Some custom message for the username required field'
}
});
});

<input name="ctl00$ContentPlaceHolder1$tbUsername" type="text" id="ctl00_ContentPlaceHolder1_tbUsername" class="username" />

If this helps you .
Please "Mark as Answer"

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response