Dear all,
I would like to generate a question in my survey, where the current number of participants rounded to the next multiple of 10 is displayed.
Qualtrics support told me I need to use Java - as I am not familiar with using Java, I'd appreciate your help!
Specifically I would like to display to the participants the text:
_"Number of participants so far: < X"_
Where X represents the next multiple of 10 of number of participants. I have already created a quota named "QuotaCount", which counts the number of participants of the survey.
Therefore the JavaScript should generate i.e. the following:
* if QuotaCount = 0 -> X=10
* if QuotaCount = 1 -> X=10
* if QuotaCount = 6 -> X=10
* if QuotaCount = 10 -> X=20
* if QuotaCount = 11 -> X=20 etc.
I have found the folowing formular online: (parseInt(x / 10, 10) + 1) * 10 - not sure though how to use it in context of the java script.
*
Looking forward to your answers.
Thank you and best regards,
Page 1 / 1
Let's say your html looks like:
```
Number of participants so far: < <span id="X"></span>
```
Then add the following js to the addOnload function:
```
var quota = parseInt("${qo://quota pipe string goes here}");
jQuery("#X").html((parseInt(quota/10, 10)+1)*10);
```
```
Number of participants so far: < <span id="X"></span>
```
Then add the following js to the addOnload function:
```
var quota = parseInt("${qo://quota pipe string goes here}");
jQuery("#X").html((parseInt(quota/10, 10)+1)*10);
```
Dear Tom,
thank you for the quick reply.
Three more questions:
* do I need to type the name of my quota 'QuotaCount' wherever you have 'quota' in your code?
* Do the " need to remain or do I replace them?
* Is there a way to test the code without clicking through the whole survey ?
Thank you very much in advance!
Best regards,
thank you for the quick reply.
Three more questions:
* do I need to type the name of my quota 'QuotaCount' wherever you have 'quota' in your code?
* Do the " need to remain or do I replace them?
* Is there a way to test the code without clicking through the whole survey ?
Thank you very much in advance!
Best regards,
Just recognized.. the HTML code: "Number of participants so far: < <span id="X"></span>"
does not remain. When qualtrics saves the question it changes to: "Number of participants so far: < " - so the reference will not remain in the html code.
Thank you very much in advance for your help!
Best regards
does not remain. When qualtrics saves the question it changes to: "Number of participants so far: < " - so the reference will not remain in the html code.
Thank you very much in advance for your help!
Best regards
> @CaBe2018 said:
> * do I need to type the name of my quota 'QuotaCount' wherever you have 'quota' in your code?
No, 'quota' is a JavaScript variable. You only need to pipe your 'QuotaCount' into the first line where it says '${qo://quota pipe string goes here}'
> * Do the " need to remain or do I replace them?
Yes, you need the quotes around your piped 'QuotaCount'
> * Is there a way to test the code without clicking through the whole survey ?
You can do a View Block from Block Options (helpful if your question is close to the top of the block)
> Just recognized.. the HTML code: "Number of participants so far: < " does not remain. When qualtrics saves the question it changes to: "Number of participants so far: < " - so the reference will not remain in the html code.
It's there, you just don't see it because the initial value inside the `<span>` is blank. It will be updated when the JS runs. You can put a placeholder inside the span (e.g., 0) if you want since it will be replaced. But the respondent may see it flash by before the actual value is set.
> * do I need to type the name of my quota 'QuotaCount' wherever you have 'quota' in your code?
No, 'quota' is a JavaScript variable. You only need to pipe your 'QuotaCount' into the first line where it says '${qo://quota pipe string goes here}'
> * Do the " need to remain or do I replace them?
Yes, you need the quotes around your piped 'QuotaCount'
> * Is there a way to test the code without clicking through the whole survey ?
You can do a View Block from Block Options (helpful if your question is close to the top of the block)
> Just recognized.. the HTML code: "Number of participants so far: < " does not remain. When qualtrics saves the question it changes to: "Number of participants so far: < " - so the reference will not remain in the html code.
It's there, you just don't see it because the initial value inside the `<span>` is blank. It will be updated when the JS runs. You can put a placeholder inside the span (e.g., 0) if you want since it will be replaced. But the respondent may see it flash by before the actual value is set.
Hi TomG,
I was able to test it and it worked!
Thank you very much!
Best regards,
I was able to test it and it worked!
Thank you very much!
Best regards,
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.