Collection multiple radio button responses using Javascript | XM Community
Skip to main content
Question

Collection multiple radio button responses using Javascript

  • November 29, 2020
  • 2 replies
  • 88 views

Forum|alt.badge.img

Picture 1.pngI have created a HTML table as above with 10 radio button responses, they are named response1 to reponse10. For example response8:

   A
   B
I am trying to use Javascript to capture all responses into an embedded data field using a list once the next button is submitted, but my code is not working:
Qualtrics.SurveyEngine.addOnReady(function() {
 var qobj = this;
 qobj.hideNextButton();
 var cbs = jQuery("#"+qobj.questionId+" input[type=radio]");
cbs.click(function() {
    numSelected = cbs.filter(":checked").length;
if(numSelected >= 10) qobj.showNextButton();
});
});
Qualtrics.SurveyEngine.addOnPageSubmit(function(type)
{
var responses=list[jQuery("#"+qobj.questionId+" input[type=radio]:checked").val()];
if(type == "next") Qualtrics.SurveyEngine.setEmbeddedData('RW1', responses);
});

2 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • November 29, 2020

The addOnPageSubmit function is wrong in a number of ways. Try:
Qualtrics.SurveyEngine.addOnPageSubmit(function(type) {
if(type == "next") {
var responses=[];
jQuery("#"+this.questionId+" input:checked").each(function() {
responses.push(this.value);
});
Qualtrics.SurveyEngine.setEmbeddedData('RW1', responses.join(","));
}
});


Forum|alt.badge.img
  • Author
  • November 29, 2020

thanks a lot, it works!