What is error in my code?

Hi there this is my jsfiddle

Which is working fine validation
But when I add this code in my validate method in js

            errorPlacement: function (error, el) {  if (el.attr('name') === 'userGender') {error.appendTo('#groupErrors'); } else error.appendAfter(el);}}

after messages then its not working

Where is error?


Use the TidyUp button after adding the code, then use the JSHint button to find and fix the obvious errors.

I believe that you can find and fix this problem yourself.

I tried TidyUp and JSHint

Not working
updated code

problem is that while I place errorPlacement block.

If I do not place that block everything is working fine

Good job - try using insertAfter instead of appendAfter

Thanks for InsertAfter
I have also Integrated CheckBox validations

But Now message of RadioButton is showing in the start not in its custom position
(I have also made some div block on/off change that’s why my code look so change then previous but that’s not an issue that was working fine)

Do you see how you have two errorPlacement functions? One of them ends up replacing the other.

You need to combine their code together, most likely by using an if/else if/else structure.

How do I differentate between them one case I am getting value using elements and in second case I am getting values using groups?

Soething like this try

but not working

It looks like you need to learn some of the basics, on how to structure else if sections.

Some good info about them are at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else

After using TidyUp it also becomes clear that you are missing a closing brace from somewhere after errorPlacement section.

Do you want to see if you can figure out where that problem lies?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.