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

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?

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.


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


Ah true! Thanks Tom.


Leave a Reply