4

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>
    &nbsp;
</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

3 Answers 3

8

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() );
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0
  1. Create a div with an id.

  2. use a selector to grab your error div.

  3. use the .add() function to add your error HTML to it.

Comments

0

Use the following structure and logic in errorPlacement option of validator to code:

errorPlacement: function(error, element){
    if("RID[]" == element.attr("name")){
        // Place error for RID[] as you want
    }else{
        // Place errors normally
    }
}

1 Comment

where should i add <div id="errorcontainer2"> in ur syntax??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.