How to add percent signs after multiple text entries | Experience Community
Skip to main content
Question

How to add percent signs after multiple text entries

  • Feb 27, 2020 7:55 PM UTC
  • 8 replies
  • 391 views

Forum|alt.badge.img+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

npetrov937
Level 2 ●●
Forum|alt.badge.img+4
  • Level 2 ●●
  • Feb 28, 2020 8:24 PM UTC
Maybe it's just me, but I can't see any code?

Forum|alt.badge.img+1
  • Author
  • Feb 28, 2020 8:27 PM UTC
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) { } }

npetrov937
Level 2 ●●
Forum|alt.badge.img+4
  • Level 2 ●●
  • Feb 28, 2020 10:38 PM UTC
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',{},'%')); } } });

MikeW
Level 5 ●●●●●
Forum|alt.badge.img+14
  • Level 5 ●●●●●
  • Sep 4, 2020 1:50 PM UTC


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.



TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Sep 4, 2020 3:31 PM UTC

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


MikeW
Level 5 ●●●●●
Forum|alt.badge.img+14
  • Level 5 ●●●●●
  • Sep 5, 2020 8:35 AM UTC

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 🙂


Forum|alt.badge.img
  • Level 1 ●
  • Aug 4, 2023 9:46 PM UTC

@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("%");

 


rgupta15
Level 4 ●●●●
Forum|alt.badge.img+8
  • Level 4 ●●●●
  • Aug 10, 2023 7:15 AM UTC

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

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