Solved
Using piped text from loop and merge in Java script
Hi,
I have a problem with using loop and merge pipe text in java script. I try to create embedded data, which will be sum of two fields, and display it on the next page. I want also to create the code which will work on with loop and merge functionality. For summing the values, i used QIDs instead of piped text, as pipe text have some problems with displaying on the next page (it seems that it ned to be reloaded, by getting back to the question from which i am taking piped text).
here is some code i wrote:
_Qualtrics.SurveyEngine.addOnPageSubmit(function()
{
var nr = "${lm://Field/1}";
var name1 = "QR"+nr+"~QID2~1~1~TEXT";
var name2 = "QR"+nr+"~QID2~1~2~TEXT";
var sum = (name1^1 + name2^1)
{
Qualtrics.SurveyEngine.setEmbeddedData("sum", sum);
}
});_
However what i have tried, it seems that loop and merge from loop and merge: ${lm://Field/1}, does not work in java script.
I would great appreciate if anyone had similar problem or know how to use loop and merge variable in the java script.
Thanks!
Piotr
Best answer by TomG
Ok, that makes a lot more sense. Besides the ^, you were missing $, (, ), and .value in your first script. However, you really don't need the loop number. Try this:
```
var inputs = $(this.questionId).select('.InputText');
var name1 = inputs[0].value;
var name2 = inputs[1].value;
var sum = (name1*1 + name2*1);
Qualtrics.SurveyEngine.setEmbeddedData("sum", sum);
```
I left out the addOnPageSubmit, because for some reason the Community gives me a Access Denied error when I include it .
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
