2

I am trying to use jquery validate plugin on my 5 questions quiz form. But I have issue with how to display the validated error message for require field.

My form is something like this:

<form id="quiz">
<table width="100%">
<tbody>
<tr id="qntr">
    <td id="qntd">My question 1</td>
    <!-- if field is empty, validate error message to appear over here -->
</tr>
<tr id="anstr">
    <td id="anstd">
    <table><tr>
        <td>Choice 1</td>
        <td>Choice 2</td>
        <td>Choice 3</td>
    </tr></table>
    </td>
</tr>
<tr id="qntr">
    <td id="qntd">My question 2</td>
    <!-- if field is empty, validate error message to appear over here -->
</tr>
<tr id="anstr">
    <td id="anstd">
    <table><tr>
        <td>Choice 1</td>
        <td>Choice 2</td>
        <td>Choice 3</td>
    </tr></table>
    </td>
</tr>
...
</tbody>
</table>
</form>

My validate.js:

$(document).ready(function() {
        var form = $("#quiz");
        form.validate({

            errorPlacement: function(error, element) {
                 error.insertAfter(x);  // what should x be?
            }

        });

});

I would like to what should be used to replace 'x' in the errorPlacement for my validate error message to show up in the of my form?

Thank you.

1
  • I'd strongly recommend that you don't use the same ID for more than one element.. Check my updated answer below! Commented Jul 21, 2010 at 8:01

1 Answer 1

3

UPDATE

Here is my updated solution:

error.appendTo(element.parents('#anstr').prev('tr'));

ORIGINAL POST

Did you try?

error.insertAfter(element);
Sign up to request clarification or add additional context in comments.

1 Comment

hi dejavu, I tried to use error.insertAfter(element), but it will appear within the Choice 1 radio button, instead of my desire location.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.