I am using jquery validate plugin to validate my form fields.
The script is like below
jQuery(document).ready(function($){
$.validator.addMethod(
"mydate",
function(value, element) {
return value.match(/^\d\d?\-\d\d?\-\d\d\d\d$/);
},
"Please enter a date in the format dd-mm-yyyy"
);
var validator = $("#signupform").validate({
rules: {
User: {
required: true,
remote: {
url: "user.php",
type: "post",
},
},
"RID[]": {
required: true,
remote: {
url: "resource.php",
type: "post",
},
},
Date: {
required: true,
mydate : true
},
},
messages: {
User: "Specify Active User",
"RID[]": "Specify Available Resource",
Date: "Specify Date"
},
errorPlacement: function(error, element) {
error.appendTo( element.parent().next() );
},
success: function(label) {
label.html("OK").addClass("checked");
}
});
which validates one of my form field
<tr>
<td style="width: 70px" class="style22" valign="top">Resource ID</td>
<td id="resource" style="width: 267px;">
<input id="resource" name="RID[]" type="text" value="" style="width: 232px" /></td>
<td class="style21" style="width: 160px" valign="top">
<img id="addScnt" alt="[+]" src="+.gif"/>
</td>
<td>
</td>
</tr>
But I want to place error for "RID[]" in a specific div <div id="errorcontainer2">
.
How can I make this possible??
Thanks in advance.. :)
blasteralfred
I solved it using custom error placement in a specific div <div id="errorbox">
errorPlacement: function(error, element){
if(element.attr("name") == "RID[]"){
error.appendTo($('#errorbox'));
}else{
error.appendTo( element.parent().next() );
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With