Trying to add labels after grid text boxes | XM Community
Skip to main content
I followed this thread



(https://www.qualtrics.com/community/discussion/102/how-to-add-static-text-after-a-text-entry-box/p1 -- extremely useful answer from Clint)



but it only works on a grid if all the boxes should have the same label.



Does anyone know of a way to apply different labels to grid text boxes

(for example, where one grid entry should say ____ days and the next should say ____ % )?
Hi @CarolK,

I'd create two more arrays, texts which should be before and after separately. Then just insert after or before the ith element of the correct array.



I haven't tested it, but I think the following code should do it:



Qualtrics.SurveyEngine.addOnload(function()

{

/*Place Your Javascript Below This Line*/



var inputs = $(this.getQuestionContainer()).select('input[type="text"]');

var my_before = ["In", "At", "On"];

var my_after = ["years", "place", "tables"];



for (var i = 0; i < inputs.length; i++) {

var input = inputs[i];

$(input).insert({before: my_before[i]});

$(input).insert({after: my_after[i]});

}

});
I tried to test that out to see if it would get me there, but it is throwing an error and I am not sure why. (But of course, I'm a beginner with Javascript, so I could be missing something simple.)
Hi @CarolK,

I used a very similar code as above in one of my surveys and it works (even now).

However, when I tried to place this code to another survey, I realized that it didn't work me too. I haven't found out why, but I've created a new version which worked me. Try it.



Qualtrics.SurveyEngine.addOnload(function()

{

var inputs = $("#"+this.questionId + ' input[type="text"]');



var my_before = ["In", "At", "On"];

var my_after = ["years", "place", "tables"];



for (var i = 0; i < inputs.length; i++) {

var input = inputs[i];

input.insert({before: my_before[i]});

input.insert({after: my_after[i]});

}



});
Not sure why, but this doesn't seem to be working for me either. But I appreciate the help - I'll have to think about this differently.
> @CarolK said:

> Not sure why, but this doesn't seem to be working for me either. But I appreciate the help - I'll have to think about this differently.



Have you tried to check your console for errors and your inspector to see if your selectors are correct? Classes and ids sometimes differ with respect to the template. Unfortunately, I don't remember which template did I use to test my code anymore...

Leave a Reply