JS to count the number of completed (single-answer multiple-choice) items on a page. | XM Community
Skip to main content

A couple of years ago I used this JS to calculate the response time for multiple items on a page. Now, I am trying to come up with a more efficient way to do this by calculating the average response time for multiple items on a page.

My overall solution is simple: use the qualtrics page timer to get the submission time for each page, then divide by the number of complete responses on the page and embed the result as Pg1AvgResponseTime (or somesuch). Where I am hitting a wall is how to easily find the number of complete responses on the page. I know I could use survey flow branches to count this based on whether each item has a selected value, or do the same thing using JS to check each item for a response; however, I have over 300 total items in this survey and am trying to avoid having to add JS or branches for all 300+ items. What I would prefer to do is have one item at the end of each page count the number of complete items on the page.
I'm a JS novice because I only use it when I absolutely need to, but I have a couple of ideas for this that I just don't know how to do:

  1. use a single code to count complete items on a page (if only!), or

  2. use a code to first list all the QIDs on a single page, then check each item (using the QIDs) for a response/response value, then create a new variable counting the responses.


Also, this would be really easy for me to do after exporting the data, but I am creating this survey for someone else so I need to have all variables built-in so the researchers can export and analyze without having to calculate new variables first. Any help would be beyond appreciated!!!

Hi there,
the challenge I see with getting the number of completed responses is that question types all have different html/DOM structures. You therefore have to check for different things depending on the question type. Do you have any insights on what type of questions will be used?
BR, Nico


Hi Nico,
Thanks for checking! The items I need response times for are all single answer multiple-choice, and each page has between 5 and 15 items followed by a page timer.
So the end of each page looks like this:
Qualtrics.PNG


Leave a Reply