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

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=listpjQuery("#"+qobj.questionId+" inputntype=radio]:checked").val()];
if(type == "next") Qualtrics.SurveyEngine.setEmbeddedData('RW1', responses);
});

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


thanks a lot, it works!


Leave a Reply