JS validations not working on Text area and selection Part

Hi There,

Can some one please guide me how should I troubleshoot one more thing. On the same link i am using JS validation for form → https://codepen.io/hmphry/pen/IFrva from the above code. It is working fine, but it doesn’t work for textarea and selections( <options>XXX</options> ).

Can someone please guide me what step should I take to troubleshoot this?

Clickable Link Here.

$(this).unbind('submit').submit();
        $(this).click();

What’re you trying to do with this set of lines? This code submits the form, but it’s in your false condition.
Also the second line is redundant.

The second problem is this line:

var index =  $(this).prevAll().length+1;

That always returns 1 because you’re wrapping things in divs, meaning there are no children directly before it.
The line only works if your form objects are siblings.

The correct line, if you only have a single form on the page, would be

var index = $(this).index('.validate')+1;

(alternatively, get rid of all the +1’s you’ve got laying around and index by 0 like a coder :wink:

Your code, working (with debug lines):

2 Likes

I have implemented your solutions, but it doesn’t work for me.

may be my HTML codes have some issues.

Your code is in a wordpress page.

Wordpress farks with jquery’s default declaration of $.

Wrap your javascript code in the following:

jQuery(document).ready(function($){
  //Your Code Here.
});
1 Like

Sir, I will update you soon.

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