tags:

views:

141

answers:

1

I am using jquery validation plugin for validation. I am using one javascript function for many forms so it is difficult to define rules for all fields for many forms.

What is the code if I want to apply a rule "required=true" for all textfields those have a class "required".

I am trying this but it is applying this rule only on first field. Remember I want to show images instead of error text message when a field in not validated.

$(obj).find("input.required").rules("add", {

 required: true,
 minlength: 2,

 messages: {

  required : "<img id='exclamation' src='images/exclamation.gif' title='This field is required.' />",
  minlength: "<img id='exclamation' src='images/exclamation.gif' title='At least 2 characters.' />"

 }
});
+2  A: 

you can use the each function:

$(obj).find("input.required").each(function(){
  $(this).rules("add", {

        required: true,
        minlength: 2,

        messages: {

                required : "<img id='exclamation' src='images/exclamation.gif' title='This field is required.' />",
                minlength: "<img id='exclamation' src='images/exclamation.gif' title='At least 2 characters.' />"

        }
  });
});
Scharrels
Perfect. This is working for me. Thanks
NAVEED
This is the only forum that I got my answer within half hour.
NAVEED