From 9a75df1fa5e166e3c6dcd039d4a30ccffd49e181 Mon Sep 17 00:00:00 2001 From: Ahmed Date: Sat, 18 Sep 2021 20:11:30 +0530 Subject: [PATCH] added quick answer --- .gitignore | 7 ++--- JavaScript Files/Quick answer reminder.js | 23 ++++++++++++++++ README.md | 2 +- examples.md | 2 +- functions/Add header rows to matrix.md | 2 +- functions/Speedy Answer.md | 32 +++++++++++++++++++++++ 6 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 JavaScript Files/Quick answer reminder.js create mode 100644 functions/Speedy Answer.md diff --git a/.gitignore b/.gitignore index 511ab9e..f4bb26d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -Scratch/* +Scratch */wip* -.history/* -wip/ \ No newline at end of file +.history +wip/ +.vscode \ No newline at end of file diff --git a/JavaScript Files/Quick answer reminder.js b/JavaScript Files/Quick answer reminder.js new file mode 100644 index 0000000..3d5364b --- /dev/null +++ b/JavaScript Files/Quick answer reminder.js @@ -0,0 +1,23 @@ +Qualtrics.SurveyEngine.addOnReady(function () { + let quest = this, + all_inputs = quest.questionContainer.querySelectorAll("[type='radio'],[type='checkbox']"); + all_inputs.forEach((ip) => { + ip.oninput = function (e) { + setTimeout(() => { + // Change the question here + let check = confirm("Yes or no"); + if (!check) { + quest.getSelectedChoices().forEach((ch) => { + quest.setChoiceValue(ch, false); + }); + } + }, 100); + }; + }); + setTimeout(() => { + all_inputs.forEach((ip) => { + ip.oninput = function (e) {}; + }); + // Change this to the delay in ms + }, 6000); +}); diff --git a/README.md b/README.md index 19de6f9..5d9659f 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ The PDFs are a good starting point for someone who has never worked with Qualtri Some points to note: -* I'm not well versed with JS _\(read as lookup function at stackoverflow\)_ and therefore some of the code may be inelegant and inefficient. Please let me know if you know how a better solution. +* I'm not well versed with JS _\(read as lookup function at stackoverflow\)_ and therefore some of the code may be inelegant and inefficient. Please let me know if you know have a better solution. * All code uploaded is working on the day it was uploaded. If it doesn't work for you, please let me know, and we'll check if it's an issue in your implementation or an update from Qualtrics. [Examples](examples.md) diff --git a/examples.md b/examples.md index 434969d..bfac8e7 100644 --- a/examples.md +++ b/examples.md @@ -15,5 +15,5 @@ 6. If they choose option 2, the question text changes, giving them an option to re-consider. 7. If they choose option 3, they are automatically redirected to the next page. -![](.gitbook/assets/external-website-error.gif) +![](../../images/external-website-error.gif) diff --git a/functions/Add header rows to matrix.md b/functions/Add header rows to matrix.md index a8c840d..0fa7906 100644 --- a/functions/Add header rows to matrix.md +++ b/functions/Add header rows to matrix.md @@ -1,6 +1,6 @@ # Add Header Row to Matrix -This function allow one to add the matrix header row at a custom location in the matrix. While Qualtrics allows repeating the header row within the table, it only does so after 5 or so rows. By using this function, one can ensure the options are visible at all times. The script below is for adding the header as the 2th row, but multiple rows can be added with slight modification. +This function allows one to add the matrix header row at a custom location in the matrix. While Qualtrics allows repeating the header row within the table, it only does so after 5 or so rows. By using this function, one can ensure the options are visible at all times. The script below is for adding the header as the 2nd row, but multiple rows can be added with slight modification. [_Link to Working Demo_](https://iima.au1.qualtrics.com/jfe/preview/SV_2rCRZYIQqNq0nzv/BL_9Hnthujr7TA2LvD?Q_SurveyVersionID=current) Hold down Ctrl or ⌘ Cmd to open the link in a new tab diff --git a/functions/Speedy Answer.md b/functions/Speedy Answer.md new file mode 100644 index 0000000..a5d74c2 --- /dev/null +++ b/functions/Speedy Answer.md @@ -0,0 +1,32 @@ +# Check for fast answers + +This function allows you to reconfirm the respondents answer if they were too fast. The idea here is to allow the respondent to slowdown a bit, helping improve data quality. + +If the respondent answers too quickly, the code below asks them to confirm their choice, if they say no, the choices are cleared. + +```js +Qualtrics.SurveyEngine.addOnReady(function () { + // Change this value to increase/decrease the time. It is in ms. + let check_time = 6000; + let quest = this, + all_inputs = quest.questionContainer.querySelectorAll("[type='radio'],[type='checkbox']"); + all_inputs.forEach((ip) => { + ip.oninput = function (e) { + setTimeout(() => { + // Change the question here + let check = confirm("Yes or no"); + if (!check) { + quest.getSelectedChoices().forEach((ch) => { + quest.setChoiceValue(ch, false); + }); + } + }, 100); + }; + }); + setTimeout(() => { + all_inputs.forEach((ip) => { + ip.oninput = function (e) {}; + }); + }, check_time); +}); +```