Get question number from javascript | XM Community
Question

Get question number from javascript

  • 16 September 2020
  • 3 replies
  • 147 views

Badge +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

Userlevel 7
Badge +27

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.

Userlevel 7
Badge +27

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

Userlevel 7
Badge +27

Ah true! Thanks Tom.

Leave a Reply