Okay I tried the following and that seems to work -

If I assign the validate class to suppose temp

then i can do -

if (mobile) {
 temp.settings.messages['phone'] = "mobile";
}
if (home) {
  temp.settings.messages['phone'] = "home";
}

Just let me know if this is fine? Seems to work.

Thanks,
Mandy.



On 5/23/07, Mandy Singh <[EMAIL PROTECTED]> wrote:

Hi Jorn,

I want to be able to customize the error messages upon form submit. For
example, for a particular field my error message should be -

"Please fill in an appropriate" + phoneNum + "number".

the phoneNum variable could be either "mobile", "office phone",
"residence" based on a drop down value.

So, the question is can I redefine some messages on form submit based on
some form field value selected/filled by the user?
Please let me know.



$(document).ready(function() {
  $.validator.setDefaults({
    debug: true
  });

  var container = $('div.container');
  // validate the form when it is submitted
  $("#form2").validate({
    errorContainer: container,
    errorLabelContainer: $("ol", container),
    wrapper: 'li',
    rules: {
      email:     { required:true, email:true },
      phone:     { required:true, minLength: 3 },
      address:   { required:true,minLength:3 }
    },
    messages: {
      email: "Please enter a valid email",
      phone: "Please enter a valid" + phoneNum,
      age:   "Please specify your age as a number (at least 3)."
    }
    //event: "keyup"
  });
});

Reply via email to