Hello, Everyone:
On page 1 of a project, I've created a dropdown menu that includes a list of names (Last Name, First Name) of the select persons who have been targeted as respondents. EXAMPLE: "Doe, John" (Intentional formatting of names for ease in data analysis later.)
On page 2, after respondents have chosen their names from the dropdown list on the previous page, I'd like to them to be greeted with a, "Hello (First Name Last Name)!" statement that reverses the format of the names from the dropdown list. EXAMPLE: "Hello, John Doe!"
I was someone would know of and be willing to share code that would reverse the display the respondents' names from the dropdown list when they appear in greeting statement on page 2. I have no idea whether what I'd like to do is possible, but I'm living with a, "there is code for everything", philosophy at the moment that I'm putting to the test.
Thank you in advance for your help.
Page 1 / 1
You can get this done without custom coding.
For the question you want to display the reversed name, create a loop and merge block. Select loop off a question. Now your field one will be populated by all the names in your dropdown list. For field 2 and field 3, enter the first and last name respectively.
In the question text, pipe the L&M fields. So it will something like
Hello ${LMField/2} ${LMField/3}
Since the respondent will select only one option, it'll only be displayed once.
Hi!
I found a solution for this:
- On your second page you insert a question with just a text box.
- In the Rich Content Editor you insert a pipe text and choose the user's answer to the question on page 1 as your content.
- Now your text on page 2 should display "Lastname, Firstname" (check it out in the preview).
- In the preview you can now inspect (dev tools --> inspect, depends on browser) the html elements and find your text box. This element is "myElement" in the below code. You might have to change the ClassName in the code below or find another way to pick the element.
- Now you add the following code as custom JavaScript code for the question on the second page (click on the questions settings --> "Add JavaScript"). Add the code in the "addOnReady" function.
myElement = document.getElementsByClassName("QuestionText BorderColor")[0];
myString = myElement.innerHTML;
myArray = myString.split(',');
myElement.innerHTML = "Hello " + myArray[1] + " " + myArray[0] + "!";
Hope this helps!
BR, Nico
AmedA, works great! Thank you so much again.
BR, Nico, thank you, too. I should have been more specific about not having permissions to insert JavaScript into Qualtrics. Completely my fault, and I'm sorry
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.