You are viewing limited content. For full access, please sign in.

Question

Question

Count Radio Button Responses

asked on October 26, 2015 Show version history

I am currently making a form and I have several radio button questions with the options "yes", "no", and "n/a." I need to count the number of "no" responses and display that number at the bottom of the form or in a message box. Can someone please help me with this?

 

Thanks, 

Dane 

0 0

Answer

SELECTED ANSWER
replied on October 26, 2015

In your form, give each radio button field the CSS class name, radio. Then have a single line field with the CSS class name, count. You can then use the following JS

$(document).ready(function () {
  $('.count input').attr('readonly', true);
  $('.radio').change(function () {
    var count=0;
    $('.radio input:checked').each(function(){
      if ($(this).val().replace(/V_/g,'')=="No") {
        count += 1;
      }
    });
    $('.count input').val(count);
  });
});

It will make the single line field read only and count how many "No" options have been selected any time a radio button field has been changed.

3 0
replied on June 2, 2021

Had to login and say thank you! This worked for a form I'm working on, too.

0 0
replied on July 12, 2021

What if I'm wanting to count the number of "Fail" radio button values in a collection?  This code works in the first group in my collection, but it doesn't work in any subsequent groups in my collection.

/*Count the # of FAILING items within an inspection*/
$(document).ready(function(){
  $('.exterior').change(function() {	//when pass/fail value is changed
    let _count = 0;
    $('.exterior input:checked').each(function(){
      if ($(this).val() === "FAIL") {
        _count += 1;
      }
    });
    $('#q106 input').val(_count);
    $('#q107').html(`FAILING ITEMS:  ${_count}`).text();
  });
});

 

0 0

Replies

replied on October 26, 2015

Is this per individual form or is it a total out of all the forms that were submitted?

0 0
replied on October 26, 2015

Thanks for your reply! I am looking to count the "no" responses per individual form.

0 0
replied on October 26, 2015

Thanks! That worked perfectly

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.