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);
});
});
How to use js to insert the question number when using question randomization within block?
Best answer by Yanan
I just figured out how to insert question numbers when using question randomization. I did some research in Qualtrics community and combined several best answers. Especially I would like to thank @TomG for his help (I really don't know how to mention people and whether I do it in a right way). He proposed the idea of using addOnPageSubmit and make the solution easier than I think.
(1) I insert an embedded data "qnumber" and set its initial value to be 1
(2) I insert "${e://Field/qnumber}" in each question body where I want to place the question number.
(3) I insert JavaScript code in each question.
Qualtrics.SurveyEngine.addOnPageSubmit(function(type)
{
if(type == "next")
{ var qnumber ="$e{ e://Field/qnumber + 1 }";
Qualtrics.SurveyEngine.setEmbeddedData("qnumber", qnumber);
}
if(type == "prev")
{ var qnumber ="$e{ e://Field/qnumber - 1 }";
Qualtrics.SurveyEngine.setEmbeddedData("qnumber", qnumber);
}
});
Sign up
Already have an account? Login
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login to the Community
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
