For example, I have a block consisting of 8 questions. I randomize the order of the questions and present one question per screen. I would like to insert the question number on each page. I saw an old discussion (attached below) in the community and implement the idea in the following step:
https://www.qualtrics.com/community/discussion/11982/adding-question-numbers-to-randomized-blocks
(1) I insert an embedded data "qnumber" and set its initial value to be 1
(2) I insert "${e://Field/qnumber}" in each question and hope it will show question numbers.
(3) I insert javascript code in each question. I tried two versions.
The first one result: question numbers increases as I click "continue" button, but it will also increase the question number when I click "previous" button. It is obviously incorrect code to use.
The second result: I tried to avoid the mistakes in version 1, but it doesn't work at all. When I click "continue" button, the question number doesn't increase as expected.
Does any of you know how to do this? Or can you help me fix my code to make it work? I am really confused. Why the second version doesn't work? Thank you very much!
version 1
Qualtrics.SurveyEngine.addOnReady(function() {
var qnumber="$e{ 1 + e://Field/qnumber }";
Qualtrics.SurveyEngine.setEmbeddedData( 'qnumber', qnumber);
});
version 2
Qualtrics.SurveyEngine.addOnReady(function() {
jQuery('#PreviousButton').click(function(event) {
var qnumber="$e{ e://Field/qnumber - 1 }"
Qualtrics.SurveyEngine.setEmbeddedData( 'qnumber', qnumber);
});
jQuery('#PreviousButton').click(function(event) {
var qnumber="$e{ e://Field/qnumber + 1 }"
Qualtrics.SurveyEngine.setEmbeddedData( 'qnumber', qnumber);
});
});
Best answer by Yanan
View original