views:

430

answers:

3

Hi all,

I'm having a real headache trying to get the jQuery Validate plugin to work.

I have a form, the first question asking the user to select an option from a radio group. This shows further questions below, depending on their selection.

What I'm trying to achieve is making the visible questions required, but obviously depending on what the user chose at the first question - ie. if the question isn't visible then don't require it.

The form can be seen here: http://planner.adamturtle.com/index.php?id=cab11f902671b3c2d6&page=2

All the javascript code is embedded on the page.

Thanks for your help.

A: 

jQuery validate plugin allows you to add a custom validation methods and you may want to try those. Inside this method you can check when is the value of the radio box and check other field values based on that information.

The method to add a custom validation is called addMethod (docs link here).

RaYell
A: 
Derek Adair
Hi Derek,Thanks for your reply.I'm sure this is possible using the validation plugins methods, so if there's a solution that way it'd be much better.I agree with your comment about removing previous attempts, I'll take those out.The PHP backend was written by me, and is very basic as I'm not a developer. I don't even think I have server side validation built in yet! That's not a priority right now, though.
Adam
Server-side validation is imperative for a live application. If you rely purely on javascript for input validation - it is possible to inject malicious content simply by disabling javascript. If you are looking for something within the jQuery validation it seems like you need to check out the documentation link that RaYell provided.
Derek Adair
+2  A: 

To gather visible elements:

$currentInputs = $("input:visible");

What I would do for readability purposes is assign all "active" inputs to be validated with a class like "validateMe":

$currentInputs = $("input.validateMe");
$result = $currentInputs.validate();
Plan B