Pull a set of characters from a text entry response in a form question | XM Community
Skip to main content
I have a form question set up with 5 text extry boxes. In the third box, respondents will enter a code in the format 0000-00000-0000... I would like to pull the middle five digits and create an embedded data field.



I thought I could use something like this, but I haven't been able to figure out how to apply it to a form question.

var str = "${e://Field/ResponseID}";

var res = str.substr(13,18);

Qualtrics.SurveyEngine.setEmbeddedData("PatientID", res);



How would I use javascript to target the third text entry box and pull the data?
```

var res = jQuery("#"+this.questionId+" input[type=text]").eq(2).val().substring(5,10);

```
Have a form question with 3 entries and want to take each of the text entries and store them in embedded data. I want all the text in each response box. I tried

var res1 = jQuery("#"+this.questionId+" input[type=text]").eq(1).val() and I got "undefined".



How do I index these questions and get the value of the response?
> @diego said:

> Have a form question with 3 entries and want to take each of the text entries and store them in embedded data. I want all the text in each response box. I tried

> var res1 = jQuery("#"+this.questionId+" input[type=text]").eq(1).val() and I got "undefined".

>

> How do I index these questions and get the value of the response?

>



I suspect that your text entries are textareas instead of inputs. Try changing the selector:

```

var res1 = jQuery("#"+this.questionId+" textarea").eq(1).val();

```

The answers are already saved, so why do you want to save them a second time in an embedded variable?
My survey is basically an application for an approval. Take an example where someone wants a permit to do something on their property. A person may use the survey several times to apply for different permits. There is alot of information that can be reused from application to application. Say one time they build a shed and now they want to landscape around the shed. They don't have to re-enter the information on where the put the shed, how big it was, what the permit number was... they can just refer to the shed and show where the landscape will be.



I have ED that I am using to pre-populate these form fields. The survey taker can update the information so the next time they apply, the updated information will be available to them.
> @diego said:

> I have ED that I am using to pre-populate these form fields. The survey taker can update the information so the next time they apply, the updated information will be available to them.

Got it. So, in your contact trigger you can update the embedded data field with the answer to the question and skip saving it as an embedded data variable. Even if you don't do that, you don't need to do it in JavaScript. You an set and embedded data variable to equal the pipe of an answer in the survey flow before the end of survey.
Let me see if I get this. In the survey flow, I would use "add below" from a block and select "set Embedded Data". Then I would Add the embedded data from the contacts list that I want to update, select "update value now" and pipe the data from the question into the embedded data field? I have an "set Embedded Data" block at the top right before an authentication block. Can I do it there or do I need to create another ED block and set the variables after the questions which are to be updated? Thanks!

Leave a Reply