I am trying to use jQuery Validator's errorPlacement to append the error message to the next TD.multiError AFTER the offending element.
There are cells with required radio inputs and I would like the message to proceed from element through the table cells until it hits one with class multiError and append the message there.
What is the correct way to do this?
- <script>
- $(document).ready(function(){
- $("#surveyForm").validate({
- errorPlacement: function(error, element) {
- if ( element.is(":radio") )
- error.appendTo( element.nextAll('td.multiError:first') );
- else if ( element.is(":checkbox") )
- error.appendTo ( element.next() );
- else
- error.appendTo( element.parent() );
- }
- });
- });
- </script>
HTML:
- <tr>
- <td class='colspan' colspan='2'><p>Which of the following most accurately describes your laboratory facility? </p></td>
- </tr>
- <tr>
- <td class='two_columns'><label><input type='radio' name='rad_22' id='ans_18' class='required' value='18' /> Private / Reference Lab</label>
- </td>
- <td class='two_columns'><label><input type='radio' name='rad_22' id='ans_19' class='required' value='19' /> Physician's Office</label>
- </td>
- </tr>
- <td class='two_columns'><input type='text' name='ans_23' id='ans_23' value='' class='required' />
- </td>
- </tr><tr><td colspan='2' class='multiError'></td></tr>
- </tr>