I have a multipart form that takes basic user information at the beginning with some jquery.validate error checking to see if the fields have been filled in and the email address is valid.
Below that there is a series of check boxes (type_of_request) for new accounts, delete accounts, new software etc which show/hide those form elements as they are checked/unchecked.
I would like to validate the required sections on the form ONLY if the corressponding type_of_request item has been checked.
Update information
That's a great solution but seems to make all of the children of the selected section required.
A typical scenario will be both the email and other checkbox in the type_request has been selected:
<div id="email" style="display: block;"> // shown because other has been selected in the type request
<input id="email_new_account" class="sq-form-field" type="checkbox" value="0" name="q4836:q1"/> // not required
<input id="email_new_account_name" class="sq-form-field" type="text" name="q4836:q2"/> // if email_new_account checked then make required
<input id="email_new_account_access" class="sq-form-field" type="text" name="q4836:q2"/> // if email_new_account checked then make required
<input id="email_new_account_manager" class="sq-form-field" type="text" name="q4836:q3"/> // if email_new_account checked then make required
<input id="email_add_remove_access" class="sq-form-field" type="checkbox" value="0" name="q4837:q1"/> // not required
<input id="email_add_remove_account_name" class="sq-form-field" type="text" name="q4837:q2"/> // if email_add_remove_access checked then make required
<input id="email_add_access" class="sq-form-field" type="text" name="q4836:q2"/> // if email_add_remove_access checked then make required
<input id="email_remove_access" class="sq-form-field" type="text" name="q4837:q3"/> // if email_add_remove_access checked then make required
</div>
<div id="other" style="display: block;"> // shown because other has been selected in the type request
<input id="other_describe_request" class="sq-form-field" type="text" name="q4838:q1"/> // required because #other was checked in type request
<input id="other_request_justification" class="sq-form-field" type="text" name="q48387:q2"/> // required because #other was checked in type request
</div>
Further Reading
I have reviewed this even further and found that the following can be added to the class of the input items
class="{required:true, messages:{required:'Please enter
your email address'}}"
or
class="{required:true, email:true, messages:{required:'Please enter
your email address', email:'Please enter a valid email address'}}"
but when I add
class="{required:'input[@name=other]:checked'}"
which was described on the http://jquery.bassistance.de site, it doesn't work. Do I need to change the syntax to get this working?