Capture response with Javascript | Experience Community
Skip to main content
Solved

Capture response with Javascript


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.

Best answer by NIcolas

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) }); ```
View original

4 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • June 14, 2018
There are a couple of different ways to do it, but the easiest is to put your JavaScript inside an addOnPageSubmit function.

  • Author
  • Answer
  • June 15, 2018
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


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

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