JavaScript Point Counter | XM Community
Skip to main content
Hi,



A beginner on JS on Qualtrics.



I am designing an experiment where the subjects have a series of 10 questions to answer. They face one question per page. For all questions, the answer has to a numerical number. A the start, they are given 1000 points (or usually called "tokens" in experimental economics). For each question, they are free to "spend" from 0 to 100 tokens maximum.



I am looking for a javascript which will provide a "token counter" where on the first page the counter display on the screen "1000 tokens" and then at each page, the counter is updated in light of their answer.



Here is what I want, example:

1. On Page 1 : display "1000 tokens".

2. They answer question 1. Say, they "spend" 50 tokens. They click on "next page".

3. On page 2: display "950 tokens".





How would you do that?





This seems the right inspiration or not? https://www.qualtrics.com/community/discussion/144/how-do-i-show-the-number-of-words-in-text-entry-boxes-i-have-several-on-the-page







Many thanks for your help!
Use an embedded data field to keep track of tokens across pages. In JS, use Qualtrics.SurveyEngine.setEmbeddedData to update the value of your embedded data field.



The post you cited doesn't pertain to your situation.
I see, thanks a lot !!
Here are my $.02...



You can use math operations with embedded data instead of JS if you prefer - see attached survey.



Note that you would need to recode your answers (this allows quite a bit of flexibility as you might have a text answer but recode it to be worth 50 points - although same applies for JS).



The main difference between JS and embedded data: embedded data necessitates that your questions are in separate blocks while with JS they can either be in separate blocks or separated by page breaks.



For more info on math operations see here.
Wow many thanks! this is a certainly a help much more than $.02! with your attached file, I can learn quicker. I was going to go with JS etc but now I will go only with the math operation, this is much simpler indeed !





Thanks!

Leave a Reply