How to add percent signs after multiple text entries | XM Community
Question

How to add percent signs after multiple text entries

  • 27 February 2020
  • 8 replies
  • 124 views

Badge +1
Hi,

I'm looking for some advice regarding adding percent signs after multiple text entries. I have been using JS (see code below) but have been adding a percent sign after the text entry box after the "Other" option. Is there a way to avoid this?

!

8 replies

Userlevel 4
Badge +4
Maybe it's just me, but I can't see any code?
Badge +1
Sorry! I've been using the following code:

var questionId = this.questionId;
var choiceInputs = $$('#'+this.questionId + ' .ChoiceStructure input');
for (var i=0; i < choiceInputs.length; i++)
{var choiceInput = choiceInputs[i]; try
{if (choiceInput && choiceInput.parentNode)
{choiceInput.parentNode.appendChild(QBuilder('span',{},'%'));
}
}
catch(e)
{
}
}
Userlevel 4
Badge +4
Hi,

You did not clarify what the type of question was. I tried replicating by what looked similar to me (there are a few ways to get to that layout) - used Side by Side.

Your updated code below (I added one conditional statement and got rid of the try and catch statements as they are not useful here). .QSF attached.

Qualtrics.SurveyEngine.addOnload(function()
{
var questionId = this.questionId;
var choiceInputs = $$('#'+this.questionId + ' .ChoiceStructure input');
for (var i=0; i < choiceInputs.length; i++) {
var choiceInput = choiceInputs[i];
if (choiceInput && choiceInput.parentNode && !choiceInput.className.includes("TextEntryBox")) {
choiceInput.parentNode.appendChild(QBuilder('span',{},'%'));
}
}
});
Userlevel 4
Badge +14


https://www.qualtrics.com/community/discussion/comment/22669#Comment_22669Hi - I'm trying to do something similar... but I just want to add percentage signs after the text boxes in ONLY the second column of my side-by-side question. I don't have any other specify questions to worry about.
I've tried:
jQuery("#"+this.questionId+" .InputText").after("%");
but I only want to do the second column in my side-by-side table.


Userlevel 7
Badge +27

https://www.qualtrics.com/community/discussion/comment/29968#Comment_29968jQuery("#"+this.questionId+" .SBS2 .InputText").after("%");

Userlevel 4
Badge +14

https://www.qualtrics.com/community/discussion/comment/29971#Comment_29971Thanks Tom - I'd previously tried...
jQuery("#"+this.questionId+" .SBS2.InputText").after("%");
...which didn't work, so I guess that space after SBS2 is important 🙂

Badge

@TomG The below code works for whole column, but i need for any one option in a column. Please give me a solution as i am new to scripting.

 #"+this.questionId+" .SBS2 .InputText").after("%");

 

Userlevel 5
Badge +8

Add a span after the choice you want the % sign and then use 

 #"+this.questionId+" .SBS2 .InputText .spanClass").after("%");

Leave a Reply