Capture response with Javascript | XM Community
Skip to main content
I need to capture the response of text entry questions (and one single choice question) to manipulate them and then store them as embedded data. I know how to identify questions IDs and how to create embedded data fields with JS, but I don't know how to get the answers after participants submit them.

Any help is appreciated.
There are a couple of different ways to do it, but the easiest is to put your JavaScript inside an addOnPageSubmit function.
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.

```javascript

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)

});

```

Hi TomG,

It Submiit the Page before API response set in Embedded field, so every time embedded fields seems to blank, Any suggestion how to submit page after API response


https://www.qualtrics.com/community/discussion/comment/28305#Comment_28305I'm not sure what you mean by API response. Post your code.


Leave a Reply