Store and Access Each Radio Button Click | XM Community
Skip to main content

I would like to store and retrieve every radio button selection in a dictionary/JSON with a timestamp for each selection.
For example, given 2 radio buttons, if a user a selects the first, then the second, then the first again, I would like data of:

[{"1": time_first_click, "2": time_second_click, "1":time_last_clicked]}

Working on another website, I have used something of this sort:

let choices = [];

let radios = document.getElementsByClassName("my-radio");


for (let radio of radios) {
  radio.addEventListener("change", (event) => {
  choices.push({selected_id:event.target.id, timestamp:Date.now()});
  document.getElementById("output").innerHTML = JSON.stringify(choices);
  });
}
I looked at this, but I can't seem to find how to make it work for my problem: https://www.qualtrics.com/community/discussion/comment/3109/#Comment_3109
I manage to do it. Here is an example. Thank you @TomG for the indication.
Capture text entry response and store it as embedded data.
Qualtrics.SurveyEngine.addOnPageSubmit(function()
{

/* Get current question ID (e.g. 'QID10') */
var qid_01_str = this.questionId;
/* console log to check what ID was capture (you can comment this line)*/
console.log('Question is: QR~' + qid_01_str)

// Save the current question's response value QR~QID247~TEXT
var responseTextField = document.getElementById('QR~' + qid_01_str);
var currentResponse = responseTextField.value;

/* console log to see what was captured */
console.log('response text entry 1 is: ' + currentResponse_01)

/* Assign response to ED */
/* The following line creates (if it doesn't exist) or set (if already exist) an embedded data value */
Qualtrics.SurveyEngine.setEmbeddedData('ed_field_name', currentResponse)
});

Be the first to reply!

Leave a Reply