Instead of duplicating a question and adding display logic to display either one depending on whether or not an embedded data field is empty, I'd like to just have javascript dynamically change the question text depending on whether or not the embedded field is empty. I've already proven I can do this by duplicating the question and adding display logic to display either one based on whether or not a person's last name is empty (after setting the embedded data after my authentication piece). I would just rather have a single question in my response output.
So far I have:
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
var text = jQuery("#"+this.questionId+" .QuestionText")
var lastname = "${e://Field/LAST_NAME}";
if(!!lastname)
text.html("We DONT HAVE your last name")
Else
text.html("We have your last name")
});
I've also tried variations on the logic to check for the null value (e.g. lastname === "", lastname is null, etc.), but I can't seem to make it work.
Solved
Is it possible to dynamically change the Question Text based on an embedded field value?
Best answer by ahmedA
Qualtrics.SurveyEngine.addOnReady(function () {
qc = this.getQuestionContainer().querySelector(".QuestionText");
lastname = "${e://Field/LAST_NAME}";
if (lastname == "") {
qc.innerText = "We DONT HAVE your last name";
} else {
qc.innerText = "We have your last name";
}
});
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.


Here's what the question would look like when the last name is missing:
And here's what the question text would look like when the last name is present: