Checkbox check/uncheck enabling | XM Community
Skip to main content
Solved

Checkbox check/uncheck enabling

  • July 14, 2021
  • 4 replies
  • 175 views

Forum|alt.badge.img+11

In the below picture I have added javascript such that if you select y for a then x also gets selected for a and similarly for b and c. Now the respondent can deselect the selection of x (as done for c) but after deselecting x for c they are not able to select x again. How do I do that using javascript. Thank you for the help in advance!!!
image.pngHere is the Javascript I used
Qualtrics.SurveyEngine.addOnReady(function()
{
jQuery('input[type="checkbox"]').change(function(){
if ( jQuery("[id='QR~QID6~1~2']").is(":checked"))
{jQuery("[id='QR~QID6~1~1']").prop('checked',true)}
if ( jQuery("[id='QR~QID6~2~2']").is(":checked"))
{jQuery("[id='QR~QID6~2~1']").prop('checked',true)}
if ( jQuery("[id='QR~QID6~3~2']").is(":checked"))
{jQuery("[id='QR~QID6~3~1']").prop('checked',true)}
});
});

Best answer by Eumetis

I just placed the code in onload and that seems to be working for me

4 replies

grahulp5
QPN Level 3 ●●●
Forum|alt.badge.img+13
  • QPN Level 3 ●●●
  • July 14, 2021

You will need to update it via tbody tr like below:
jQuery('.QuestionBody').find('ul li').change(function() 
{
if (jQuery(this).find('input[type="checkbox"]').eq(1).is(':checked')) {
jQuery('.QuestionBody .ChoiceStructure').find('tbody tr td').find('input[type="checkbox"]').eq(0).prop('checked',true)}

});


Forum|alt.badge.img+11
  • Author
  • QPN Level 5 ●●●●●
  • July 14, 2021

https://community.qualtrics.com/XMcommunity/discussion/comment/39055#Comment_39055hi, this doesn't seem to work! Could you explain what exactly it does as my javascript is a bit weak!


grahulp5
QPN Level 3 ●●●
Forum|alt.badge.img+13
  • QPN Level 3 ●●●
  • July 14, 2021

You have used qids and hence would require to write if logic for every scenario, the best would be write .click() or .change() function which would save your time. Do update the code accordingly, and try to break the code piece by piece; that might help.


Forum|alt.badge.img+11
  • Author
  • QPN Level 5 ●●●●●
  • Answer
  • August 27, 2021

I just placed the code in onload and that seems to be working for me