Solved
Using JavaScript to set "FIRST NAME" to titleCase "First Name"
Has anyone found a way to fix all caps embedded data, like "NAME", into something like "Name"?
I think this should be doable with piped text, .setEmbeddedData, and a JS expression to convert the piped text to titleCase.
I've tried:
Qualtrics.SurveyEngine.setEmbeddedData('Value_2', titleCase("${e://Field/Value_1")));
But it didn't work. I'm thinking I first need to correct "Value_1" before I can set it to "Value_2.
Best answer by Yash
Hi,
You can define a function for it and set the value accordingly. Please use below code, it's working fine for me.
var name = "${e://Field/Name}"
var name2 = toTitleCase(name);
function toTitleCase(str) {
return str.replace(
/\\w\\S*/g,
function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
}
);
}
Qualtrics.SurveyEngine.setEmbeddedData('Name2',name2);
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
