Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. <ol type="a">
  2. <li><input type="radio" name="answer0[]">A</li>
  3. <li><input type="radio" name="answer0[]">A</li>
  4. <li><input type="radio" name="answer0[]">A</li>
  5. </ol>
  6. <ol type="a">
  7. <li><input type="checkbox" name="answer1[]">A</li>
  8. <li><input type="checkbox" name="answer1[]">A</li>
  9. <li><input type="checkbox" name="answer1[]">A</li>
  10. </ol>
  11.  
  12. $('ol').each(function (i) {
  13. $(this).find("input:first").prop("required", true);
  14. });
  15.  
  16. $('ol').each(function (i) {
  17. $("[name='answer"+i+"[]']").rules("add", {required:true});
  18. });
  19.  
  20. var rules = {};
  21.  
  22. $('ol [type="checkbox"], ol [type="radio"]').each(function(i,el){
  23. var name = $(el).attr('name');
  24. if(rules[name] === undefined){
  25. rules[name] = {
  26. required: true
  27. };
  28. }
  29. });
  30.  
  31. $("#myform").validate({
  32. rules: rules
  33. });
  34.  
  35. $('ol').each(function (i) {
  36. $(this).find("input[type='checkbox']").prop("required", true);
  37. });
  38.  
  39. $('ol').find('input[type="checkbox"]:checked').length
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement