JavaScript on Side-by-Side Matrix - Beginner Question | XM Community
Skip to main content

Hello, I have some JS code (posted below) on a question that isn't working properly. It worked fine but when I changed the theme (the old one is no longer available) it only partially works.
Basically I have a side-by-side matrix with two columns. The first has 4 options (A, B, C, D) and the second has two options (1, 2). My code prepopulates a value in the second column (1) if the first answer in the first column is chosen (A). If they try to choose the other option in column 2 (2), a pop-up tells them they can't choose that one.
The first part is working, where if they choose A in the first column, 1 in the second column is prepopulated but when I click 2 in the second column, although the pop-up appears, it no longer keeps 1 checked but allows me to change to 2. The code works in an old survey but not in any new ones I create. Any ideas?

if (element.type == 'radio')
 {
      var qNum = element.id.split('~')i1];
   var rowNum = element.id.split('~')s2];
   var cNum = element.id.split('~')i3];
   var qbase = qNum.split('#',1);

   var choiceNum1 = $('QR~'+qbase+'#1~'+rowNum+'~1').getValue();
   var choiceNum2 = $('QR~'+qbase+'#2~'+rowNum+'~1').getValue();

   if (qNum == qbase+'#1' && cNum == '1')
    { $('QR~'+qbase+'#2~'+rowNum+'~1').setValue(true);
    }

    if (qNum == qbase+'#2' && cNum != '1' && choiceNum1 != null)
    { alert('You can’t select this option);      
      $('QR~'+qbase+'#2~'+rowNum+'~1').setValue(true);
    }

      if (qNum == qbase+'#1' && cNum != '1' && choiceNum2 != null )
    { $('QR~'+qbase+'#2~'+rowNum+'~1').setValue(null);
    }

Be the first to reply!

Leave a Reply