views:

31

answers:

1

here is my code:

groups: {
    phone: "phone1-phone2-phone3"
   digits: true
},
errorPlacement: function(error, element) {
    if (element.attr("name") == "phone1" 
           || element.attr("name") == "phone2" || element.attr("name") == "phone3")
        error.insertAfter("#telephone");
    else
    error.insertAfter(element);
},
debug:true

here is my form input text:

<p><label for="name"><span class="red">*</span>Phone: </label> <input type="text" name="phone1" id="phone1" size="3" tabindex="12" />-<input type="text" name="phone2" id="phone2" size="3" tabindex="12" />-<input type="text" name="phone3" id="telephone" size="4" tabindex="12" /></p>

the above didnt validate? any ideas is much appreciated!

A: 

the input ids in groups must be delimited by spaces not -. Here is the code

$("#form").validate({
groups: {
  phone: "phone1 phone2 telephone"
},
rules: {
  phone1 : "digits",
  telephone : "digits",
  phone2 : "digits"
},
onsubmit: false,
errorPlacement: function(error, element) {
    if (element.attr("name") == "phone1"
           || element.attr("name") == "phone2" || element.attr("name") == "phone3")
        error.insertAfter("#telephone");
    else
    error.insertAfter(element);
},
debug:true
});

The rules need to be specified under the rules option

Vinodh Ramasubramanian
can i add another group to the list like this:groups: { phone: "phone1 phone2 phone3", cell: "cell1 cell2 cell3" },errorPlacement: function(error, element) { if (element.attr("name") == "phone1" || element.attr("name") == "phone2" || element.attr("name") == "phone3") error.insertAfter("#telephone"); else if (element.attr("name") == "cell1" || element.attr("name") == "cell2" || element.attr("name") == "cell3") error.insertAfter("#cellu"); else error.insertAfter(element); },
Menew
I don't know. will need to try it. Why don't you use the JSbin page I set up to test it?
Vinodh Ramasubramanian