Get question number from javascript | XM Community
Skip to main content
Question

Get question number from javascript

  • September 15, 2020
  • 3 replies
  • 284 views

Forum|alt.badge.img+1

I would like to be able to use user defined question numbers as logic in my javascript. For example, to distinguish between questions where the previous button should be enabled vs questions where it is hidden, such as in this example where I want to hide the previous button on all question numbers that start with "F..."

if(question_number.charAt(0) == "F"){ this.hidePreviousButton(); }

I originally thought that using
Qualtrics.SurveyEngine.QuestionInfo 
or
this.questionId 
would return the question number, but they only return the internal ID, which isn't helpful.
So far, the only way I have found to get the question number is to select the option "Show Question Numbers" in "Survey Options", use
jQuery("#"+this.questionId+" .ExportTag").hide();
to hide them, and then inspect then inspect the contents of the ExportTag HTML label.
Is there any other way of getting the question number in javascript?

3 replies

Tom_1842
Level 8 ●●●●●●●●
Forum|alt.badge.img+28
  • Level 8 ●●●●●●●●
  • November 17, 2022

Hi there, if you still need, you can save the Question Export tag value as a var by using the below:
var qtag = jQuery("#"+this.questionId+" .ExportTag").html();
jQuery("#"+this.questionId+" .ExportTag").hide();
console.log(qtag);
I believe you will need to have "Show Question Numbers" enabled.


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • November 17, 2022

Since the export tag has a period at the end, I think you want:
var qtag = jQuery("#"+this.questionId+" .ExportTag").text().slice(0,-1);


Tom_1842
Level 8 ●●●●●●●●
Forum|alt.badge.img+28
  • Level 8 ●●●●●●●●
  • November 18, 2022

Ah true! Thanks Tom.