My problem is very similar to this post: Validate subset of form using jQuery Validate Pugin, but couldn't get anything to work. I'm trying to use the jquery validation plugin to do partial form validation in an onclick js function.
I have a view that has a form with many divs, each div represents a page like so:
<form method="post" name="surveyForm" id="surveyForm>
<div id="pageNav">
<input id="prevButton" type="button" onclick="PrevPage();" value="Back" />
<input id="nextButton" type="button" onclick="NextPage();" value="Next" />
</div>
<div id="page_1">
Question 1
<input id="q1_opt1" name="q1" type="radio" value="Yes" />Yes
<input id="q1_opt2" name="q1" type="radio" value="No" />No
</div>
<div id="page_2">
Question 2
<input id="q2_opt1" name="q2" type="radio" value="Yes" />Yes
<input id="q2_opt2" name="q2" type="radio" value="No" />No
</div>
<button type="submit">Submit Survey</button>
</form>
My NextPage() js function hides and shows divs to get a wizard effect to step through the questions. This is where I want to do the validation to make sure the inputs in that div are validated. The inputs within a div could be a group of radiobuttons where at least one selection is required or a single textbox that requires entry before moving on.
//on initialize I hide all page_# divs except page_1
var curPage=1;
function NextPage()
{
//****WANT TO DO VALIDATION HERE
// Cancel page change if validation fails
$("#page_" + curPage.toString()).hide(); //hide current page div
curPage++; //increment curpage
$("#page_" + curPage.toString()).show(); //show new current page div
}
How would I use jquery validator to accomplish this type of partial form validation?