Forums

JS Multi Checkbox Validation

berlin80210 07 Dec, 2015
Hello,

I am following the steps outlined here with no success:
http://www.chronoengine.com/forums/posts/f26/t66192/js-checkbox-validation-help.html?hilit=checkbox+validation

I have JS enabled with the following snippit:

window.addEvent('domready', function() {

  $('Vote1').addClass("validate['%countCheck']");
});
var countCheckMax = 3;
var countCheckMin = 3;
function countCheck(el){
  var group = el.getSiblings(['input']);
  group.include(el);
  var count = 0;
  group.each(function(item) {
    if ( item.checked ) {
      count++;
    }
  });
  if ( count > countCheckMax ) {
    el.errors.push("You can only check "+countCheckMax+" items");
    return false;
  } else if ( count < countCheckMin ) {
    el.errors.push("Please check at least "+countCheckMin+" items");
    return false;
  } else {
    return true;
  }
}



Here is my form code:

<div><h2 class="uk-margin-bottom-remove"><img src="images/BOD/Rebecca.png" alt="Rebecca" width="200" height="211" class="img_phone" style="border-radius: 100px; margin: 20px; float: left;" />Rebecca Browning<br /><br /></h2>
<p><strong>Why are you are interested in serving on the NAPMDD Board of Directors?</strong> PMDD is a big part of my life. I feel like having a position on the board or a committee chair will help me be in the forefront of new information. I want to learn and to continue to support my peers. <br /><br /><strong>What strengths you could bring to the Board?</strong> I am Organized. I would work hard for the goals of the organization. I work well with others and have a positive attitude. <br /><br /><strong>How does PMDD and premenstrual health inspire you?</strong> I am inspired to find a cure, meet women who suffer and help the women find what can help them deal with the symptoms. I want to help the organization gain more exposure. </p>
<p><strong>What are your other volunteer activities / hobbies / personal interests?</strong> I am involved in PTO. I help in the classroom at times. My husband owns a costume rental shop. I really enjoy helping him out at the shop. It is great creative therapy. I like to donate my time in the community to help with events on an in and out basis. I am also involved in Women's Lead organization locally. My main interest in life is my family.</p><br /></div>
<div class="gcore-input-wide gcore-display-table" id="fin-Vote"><div class="gcore-single-column" id="fclmn"><div class="gcore-checkbox-item" id="fitem"><input name="checkbox_group12[]" id="Vote"  title="" style="" data-load-state="" data-tooltip="" type="checkbox" value="&nbsp;Rebecca Browning" />
<label class="control-label gcore-label-checkbox" for="Vote">Vote for Rebecca</label></div>
<br />
<div><h2 class="uk-margin-bottom-remove"><img src="images/BOD/Kate.png" alt="Kate Cavasin" width="200" height="211" class="img_phone" style="border-radius: 100px; margin: 20px; float: left;" />Kate Cavasin<br /><br /></h2>
<p><strong>Why are you are interested in serving on the NAPMDD Board of Directors?</strong> Having pmdd, I feel as though I would be able to give good insight with my peers. My sister has also been diagnosed and we, together, have done a lot of research and talk daily about it.<br /><br /><strong>What strengths you could bring to the Board?</strong> I suffer from PMDD, anxiety and depression and can show empathy and sympathy towards those going through these disorders. I was a leader with weight watchers for 3 years before moving. <br /><br /><strong>How does PMDD and premenstrual health inspire you?</strong> It inspires me because I want to get the word out about this disorder. Before talking to my sister and ultimately getting diagnosed, I had no idea what pmdd was....and even still, most people I speak to have no clue.</p>
<p><strong>What are your other volunteer activities / hobbies / personal interests?</strong> Honestly, these last 2 years have been the most crippling I've had in my life. I don't do much outside of raising my children, cleaning, cooking and being with my husband who is in the Canadian Forces.</p>
<br /> </div>
<div class="gcore-checkbox-item" id="fitem1"><input name="checkbox_group12[]" id="Vote1"  title="" style="" data-load-state="" data-tooltip="" type="checkbox" value="&nbsp;Kate Cavasin" />
<label class="control-label gcore-label-checkbox" for="Vote1">Vote for Kate</label></div>
<br />
<h2 class="uk-margin-bottom-remove"><img src="images/BOD/Andrea.png" alt="Andrea Chisholm, MD" width="200" height="211" class="img_phone" style="border-radius: 100px; margin: 20px; float: left;" />Andrea Chisholm, MD<br /><br /></h2>
<p><strong>Why are you are interested in serving on the NAPMDD Board of Directors?</strong> I am a practicing OB/GYN and the About.com PMS/Menstrual Disorders expert.This medical condition is very important to me and I am very interested in improving awareness and access to appropriate care.<br /><br /><strong>What strengths you could bring to the Board?</strong> My medical expertise and enthusiasm<br /><br /><strong>How does PMDD and premenstrual health inspire you?</strong> This is a very real medical problem that is too often ignored or not treated correctly.</p>
<p><strong>What are your other volunteer activities / hobbies / personal interests?</strong> Writing</p>
<br />
<div class="gcore-checkbox-item" id="fitem2"><input name="checkbox_group12[]" id="Vote2"  title="" style="" data-load-state="" data-tooltip="" type="checkbox" value="&nbsp;Andrea Chisholm MD" />
<label class="control-label gcore-label-checkbox" for="Vote2">Vote for Andrea</label></div>
<br />
<div>


<h2 class="uk-margin-bottom-remove"><img src="images/BOD/Jennifer.png" alt="Jennifer" width="200" height="211" class="img_phone" style="border-radius: 100px; margin: 20px; float: left;" />Jennifer Jorrey<br /><br /></h2>
<p><strong>Why are you are interested in serving on the NAPMDD Board of Directors?</strong> I am interested in serving as a Board Member at Large because I want to become a larger part of this growing organization. I would like to offer my professionalism, compassion and knowledge to the NAPMDD board of directors.<br /><br /><strong>What strengths you could bring to the Board?</strong> Leadership: I currently serve as a leader for several organizations.  My ultimate goal as a leader is to enrich the experience of the people in each organization. Leadership positions include "Lean In" leader for a circle of women in central Ohio (leanincircles.org); Section Representative for OBTA­ An Association for Business and Technology Teachers; Department Chair for the electives department at the school where I teach; Advisor for Business Professionals of America (student organization); and Facebook admin to Reynoldsburg, OH neighbors, Reynoldsburg Mama Friends and Positive Women Sharing (PWS). Teaching: I am a formally trained and licensed teacher. I have natural presentation skills and am able to teach people of all levels of understanding and background knowledge. I would like to offer my skills as a presenter/teacher to assist with the goals of NAPMDD. My teaching background is business so I would be useful in assisting with any marketing and financial initiatives. Other strengths include professionalism, organization, networking, advocacy, and support.<br /><br /><strong>How </strong>does<strong> PMDD and premenstrual health inspire you?</strong> PMDD is near and dear to my heart because I am a long­time sufferer. I have been suffering with PMDD for over 20 years. As a teenager, I let my parents know how I was feeling and my dad told me that, "it [was] just my hormones". Little did I know how right he was. Over the next couple of decades I would consistently suffer through all of the symptoms each month.  I was misdiagnosed time and time again with depression, but I could not shake the fact that I had at least one really good week each month. I decided to start some serious research to find out what was wrong with me which is when I discovered PMDD. This revelation gave me the solid ground to start talking with my family about what was happening with me. I reached out and found multiple support groups on Facebook and then came across NAPMDD. I owe everything to the current support group that is out there and really want to be part of the support and advocacy myself. This is why it inspires me.</p>
<p><strong>What are your other volunteer activities / hobbies / personal interests?</strong> Volunteer Activities­, Lean In Circles, empowering women to lean in at home and work; Big Brothers/Big Sisters, working with teenage girls to help them develop into strong young women Hobbies­ Photography / Product Photography, Crafting, Reading / Research, Movies, Traveling Personal Interests­ Networking, Social Groups, Entrepreneurship, Continuing Education</p>
<br />

</div>

<div class="gcore-checkbox-item" id="fitem3"><input name="checkbox_group12[]" id="Vote3"  title="" style="" data-load-state="" data-tooltip="" type="checkbox" value="&nbsp;Jennifer Jorrey" />
<label class="control-label gcore-label-checkbox" for="Vote3">Vote for Jennifer</label></div>
<br />
<div>

<h2 class="uk-margin-bottom-remove"><img src="images/BOD/Jameelah.png" alt="Jameelah" width="200" height="211" class="img_phone" style="border-radius: 100px; margin: 20px; float: left;" />Jameelah Medina<br /><br /></h2>
<p><strong>Why are you are interested in serving on the NAPMDD Board of Directors?</strong> I am interested in serving on the board as a member because I am passionate about PMDD and would love the opportunity to help lead the direction of NAPMDD.<br /><br /><strong>What strengths you could bring to the Board?</strong> I would bring my leadership skills and my academic background in women's issues, as well as my own experiences living with PMDD. As an African American woman, I also think I would bring a different perspective.<br /><br /><strong>How </strong>does<strong> PMDD and premenstrual health inspire you?</strong> PMDD and premenstrual health inspire me because it directly affects me and women I know. It inspires me because I have a chance to do something about it by educating and supporting women with it.</p>
<p><strong>What are your other volunteer activities / hobbies / personal interests?</strong> My hobbies include: writing, reading and swimming, as well as playing with my toddler My personal interests include: women's issues, interfaith issues, psychological issues, multicultural and diversity issues. My volunteer activities include: crisis intervention counseling, The Prison Library Project, Sage Open Journal reviewer, International Journal of Sociology and Anthropology reviewer, writing on multiple blogs, Coalition Against Sexual Exploitation Outreach and Education Committee member, Rape Abuse and Incest National Network Speakers Bureau member, and other organizations of which I am a member.</p>
<br />
</div>

<div class="gcore-checkbox-item" id="fitem4"><input name="checkbox_group12[]" id="Vote4"  title="" style="" data-load-state="" data-tooltip="" type="checkbox" value="&nbsp;Jameelah Medina" />
<label class="control-label gcore-label-checkbox" for="Vote4">Vote for Jameelah</label></div>
<br />
<div>

<h2 class="uk-margin-bottom-remove"><img src="images/BOD/AmandaP.png" alt="Amanda Parodi" width="200" height="211" class="img_phone" style="border-radius: 100px; margin: 20px; float: left;" />Amanda Parodi<br /><br /></h2>
<p><strong>Why are you are interested in serving on the NAPMDD Board of Directors?</strong> I would love to be the voice for Antibiotic Therapy in treating PMDD. Receiving this therapy myself has reduced my symptoms by 80%.<br /><br /><strong>What strengths you could bring to the Board?</strong> I am passionate about helping women feel better, about getting past the worst of their symptoms, about feeling healthy and strong. My passion is my greatest strength.<br /><br /><strong>How </strong>does<strong> PMDD and premenstrual health inspire you?</strong> I was diagnosed with PMDD after suffering from it for over a year. I didn't realize that I had moderate PMS before that, and I've realized that even mild to moderate PMS can really affect a woman's life, and even if it's not as severe as PMDD, it still needs to be addressed. 80% of women are dealing with some form of PMS, and they all need help.</p>
<p><strong>What are your other volunteer activities / hobbies / personal interests?</strong> I am one of Jehovah's Witnesses, and I volunteer 4­6 hours a week, mainly on the weekends, looking for people who want a solution to this world's problems. I see antibiotic therapy as a HUGE help for women with PMDD, but ultimately, I see the Bible's promise of a paradise earth and a time when no one will say "I am sick" (Isaiah 33:24) as the ultimate solution.</p>

</div>


<div class="gcore-checkbox-item" id="fitem5"><input name="checkbox_group12[]" id="Vote5"  title="" style="" data-load-state="" data-tooltip="" type="checkbox" value="&nbsp;Amanda Parodi" />
<label class="control-label gcore-label-checkbox" for="Vote5"> Vote for Amanda</label></div></div></div></div>
<br /><br />
<div class="form-group gcore-form-row" id="form-row-button"><div class="gcore-input gcore-display-table" id="fin-button"><input name="button" id="button" type="submit" value="Submit My Votes" class="btn" style="" data-load-state="" /></div></div>



Your urgent assistance is appreciated! Thank you!
GreyHead 08 Dec, 2015
Answer
1 Likes
Hi berlin80201,

The old example you found was using the MooTools library from a previous version of Joomla! and ChronoForms. I had a similar script that I've adapted to work with your code. You can see my test here. Here's the script that page is using:
jQuery(document).ready(function(jQ){
  var votes;
  votes = jQ("input:checkbox[name='checkbox_group12[]']");
  votes.on('click', checkCount);
  // disable the submit button
  jQ('#button').prop('disabled', true);

  function checkCount() {
    var votes_checked;
    votes_checked = jQ("input:checkbox[name='checkbox_group12[]']:checked");
    if ( votes_checked.length >= 3 ) {
      jQ('#button').prop('disabled', false);
      votes.each(function (){
        if ( !jQ(this).prop('checked') ) {
          jQ(this).prop('disabled', true);
        }
      });
    } else {
      jQ('#button').prop('disabled', true);
      votes.each(function () {
        jQ(this).prop('disabled', false);
      });
    }
  }
});
The action here is to disable/enable the submit button and disable the other checkboxes once three are checked.

Bob
berlin80210 08 Dec, 2015
Thank you so much! I added your script and it works perfect. 😀
This topic is locked and no more replies can be posted.