Collection multiple radio button responses using Javascript | XM Community
Question

Collection multiple radio button responses using Javascript

  • 29 November 2020
  • 2 replies
  • 58 views

Badge

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

Userlevel 7
Badge +27

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(","));
}
});

Badge

thanks a lot, it works!

Leave a Reply