Custom javascript with a multiple choice not working anymore with simple layout | XM Community
Skip to main content
Question

Custom javascript with a multiple choice not working anymore with simple layout

  • July 30, 2025
  • 2 replies
  • 35 views

Forum|alt.badge.img+4

Hello,

 

I’m switching a project to simple layout and one of my custom javascript isn’t working any more.

part of the code is this one :

    this.questionclick = function (event, element) 
    {
        var selectedDisruptions = [];
        var EligibleDisruptions = [];
        var isdisrupt = '';

        jQuery('#QID57 input:checked').each(function(btn)
        {
            if (this.id.split('~')[2] != '1') {
                selectedDisruptions.push(choiceDict[this.id.split('~')[2]]
                isdisrupt = 'Y';            
            }
            if (this.id.split('~')[2] == '1') {
                isdisrupt = 'N';
                selectedDisruptions.push(choiceDict[this.id.split('~')[2]])           
            }         
        });
    };

 

The jquery isn’t working anymore evenif i add “<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>” in the header part.

 

What do I need to change here “jQuery('#QID57 input:checked').each(function(btn)“.

 

Thanks advance

 

regards 

2 replies

rochak_khandelwal
Level 5 ●●●●●
Forum|alt.badge.img+31
  • Level 5 ●●●●●
  • 170 replies
  • July 31, 2025

Hey,

I think this.getQuestionContainer() method should help within Simple Layout.
 

this.questionclick = function(event, element) {
var selectedDisruptions = [];
var isdisrupt = '';

var qContainer = this.getQuestionContainer(); // Get scoped question container
jQuery(qContainer).find('input:checked').each(function() {
var idPart = this.id.split('~')[2];
if (idPart != '1') {
selectedDisruptions.push(choiceDict[idPart]);
isdisrupt = 'Y';
} else {
isdisrupt = 'N';
selectedDisruptions.push(choiceDict[idPart]);
}
});
};


Do let me know if it works.
-- Rochak


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 6084 replies
  • July 31, 2025
  1. Replace “#QID57” with “#question-QID57”
  2. Replace “this.id.split('~')[2]” with “this.id.split('-')[4]