0

I have a form with the following format:

<form id="program" name="program method="get" action="process.jsp">

<div id="add">
some input box here...........
<input type="submit" name="action" value="Add">

</div>

<div id="exit">
some input box here...........
<input type="submit" name="action" value="Exit">

</div>

<div id="refuse">
some input box here...........     
<input type="submit" name="action" value="Refuse">

</div>

</form>

My jquery code validation is:

$("#program").validate({
          errorClass: "error",
          rules: {
       doentry: {
           required: true,
           date: true
       },
       doe: {
           required: true,
           date: true
       },
       dor: {
           required: true,
           date: true
       },
       cid: {
           selectNone: true
            }
         }
            });

where dor, doe, doentry is an <input> that is in different div, the problem is when I click on submit, on a div that is currently visible (not hidden), it requires all the other elements in the other div's that is currently hidden to be validated as well... which I don't want! What's the best way to solve this just by modifying the jQuery.. so only it validates the elements that is inside a div that is currently visible and not the whole form.

2
  • 1
    You're aware of the fieldset and label elements, right? Commented Dec 4, 2010 at 17:01
  • Ehmm...so you mean instead of div's I should use fieldset? Commented Dec 4, 2010 at 17:02

1 Answer 1

1

The validation plugin has an ignore option, use that with the :hidden selector to ignore elements that aren't visible, like this:

$("#program").validate({
      ignore: ":hidden",
      errorClass: "error",
      //rules, etc..
});
Sign up to request clarification or add additional context in comments.

2 Comments

are you missing a closing quote on the hidden?
@EquinoX - oops, indeed I was, fixed!

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.