My problem is very similar to this post: Validate a subset of a form using jQuery Validate Pugin , but cannot make anything work. I am trying to use the jQuery validation plugin to partially validate a form in the onclick js function.
I have a view that has a form with many divs, each div represents a page like this:
<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>
The MyJetPage () js function hides and shows divs to get the wizard effect to get through the questions. This is where I want to do validation to make sure the input in this div is validated. The inputs to the div can be a group of ham enthusiasts where at least one choice or one text block is required that requires input 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 can I use jquery validator to validate this type of partial form?
source share