How to create an auto-checked checkbox after all options are satisfied? | XM Community
Skip to main content
Question

How to create an auto-checked checkbox after all options are satisfied?


Hello all,
I'd like to create a checkbox next to my question that automatically check itself after all options are checked. Is that possible?
For example, after checking all choices 1,2 and 3, I want a checkbox on the left of my question to check automatically.

Can someone please help me out?

Thanks.
image.png

Tom_1842
Level 8 ●●●●●●●●
Forum|alt.badge.img+28
  • Level 8 ●●●●●●●●
  • June 23, 2023

Hi, this can be put in place by including a checkbox in the question text and then using JS to check if the selected choice amount is equal to the total amount of choices and setting the checkbox to checked if true. Try adding the below to the question text using the Rich Content Editor’s HTML/Source view:

Click to write question text.<br>
<input type="checkbox" name="allcheck" id="allcheck" class="allcheck"> <label>All Checked</label>

Then add the below to the question’s JavaScript in the OnReady section:

var allcheck = document.getElementById('allcheck');
var totalchoices = jQuery("#"+this.questionId+" .ChoiceStructure").children().length;

this.questionclick = function(event,element)
{

var selChoices = this.getSelectedChoices();
var checks = selChoices.length;

if (checks === totalchoices) {
allcheck.checked = true;
} else {
allcheck.checked = false;
}

}

Finally, add the below CSS to the Style section of the Look & Feel:

#allcheck {
position: relative !important;
opacity: 1 !important;
z-index: 999 !important;
height: 20px !important;
width: 20px !important;
}

 


Forum|alt.badge.img+20
  • QPN Level 5 ●●●●●
  • June 23, 2023

@Tom_1842 that works! 


Leave a Reply