javascriptjqueryjquery-validate

How to display the jquery validation error message in popup?


I want display the Postcode field error message in popup. Other fields error message not needed popup.I have used the below code. How solve this.

$(document).ready(function() {

$("#conference_form").validate({
   rules: {
        conpostcode:  {
            required: true,    
             minlength: 4, 
            remote: {
                url:"<?php echo base_url() ?>tools/check_postcode/1",
                type: "post",
              data:
                      {
                          postcode: function()
                          {
                              return $('#conpostcode').val();
                          }
                      },

            }           
          },
         name: "required",
         address: "required",
                   date: "required",
         description:"required",

    },
    messages: {
        conpostcode: "We don't have service this location, Please call us +44 12345454, for stock sets support.",
         name: "Please enter venu name",
         address: "Please enter address",
         date: "Please enter date",
         description: "Please enter description",


    }

})

});

How display the postcode error message only in alert or popup. Please any one help.


Solution

  • Use errorPlacement option

    errorPlacement (default: Places the error label after the invalid element) Type: Function() Customize placement of created error labels. First argument: The created error label as a jQuery object. Second argument: The invalid element as a jQuery object.

        errorPlacement: function(error,element){ 
                            //error.insertAfter(element); 
                            //use error.html() as content in your popup div or simply
                            alert(error.html());             
                         }