Adding Radio Buttons to Constant Sum with Multiple Columns | XM Community
Question

Adding Radio Buttons to Constant Sum with Multiple Columns

  • 9 September 2020
  • 0 replies
  • 34 views

Userlevel 1
Badge

Hi all,
I have a piece of JavaScript which creates a radio button for a specified row in a singular constant sum question. When the button is selected, the total becomes 100.
However, I am trying to implement this same concept to a constant sum question with two columns instead of one. I am a bit stumped on the correct route to address. I am not too familiar with the Qualtrics API just yet.
Here is the code which works for the singular column:
Qualtrics.SurveyEngine.addOnReady(function()
{
/* SETTINGS */
var row=3; /* what row is the "don't know" row? */
/* END OF SETTINGS */
var qid=this.questionId;
var dk = document.getElementsByName("QR~"+qid+"~"+row); 
for (i = 0; i < dk.length; i++) {
dk[i].type = "radio";
}
var inputs = $(this.getQuestionContainer()).select('input[type="text"]');
dk[0].onclick = function(){ 
for (var i = 0; i < inputs.length; i++) {
inputs[i].value="0";
}
dk[0].value = "100"; 
}
for (var i = 0; i < inputs.length; i++) {
var input = inputs[i];
$(input).insert({after: ' %'});
inputs[i].onclick = function(){
dk[0].value = "0"; 
dk[0].checked=false;
}
}
dk[0].style.zIndex = "auto";
dk[0].style.opacity = "1";
dk[0].style.height = "1em";
});
Can anyone direct me on how I can get this to work so the Don't Know Button shows up in both columns? I assume it has to do with the use of the row variable declared in the dk variable and there needs to be additional code to execute the same sequence for the second column, but I am stumped.
Any suggestions is much appreciated. Thanks


0 replies

Be the first to reply!

Leave a Reply