-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCharacter Limit Reminder.js
31 lines (26 loc) · 1.08 KB
/
Character Limit Reminder.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Qualtrics.SurveyEngine.addOnload(function()
{
//Create a placeholder to display the reminder message
char_rem = document.createElement("p");
char_rem.setAttribute("id", "char_reminder");
char_rem.setAttribute("style", "color:LightGray;");
this.getChoiceContainer().parentNode.appendChild(char_rem);
});
Qualtrics.SurveyEngine.addOnReady(function()
{
const qid = this.questionId;
document.querySelector("#QR\\~" + qid).oninput = function () {limited();};
function limited(){
curr_len = document.querySelector("#QR\\~" + qid).value.length;
//Set the max_len as an embedded data field equal to maximum length in validation options
max_len = "${e://Field/max_len}";
//Nothing will be displayed if the characters are less than 10
//If you want to always have the reminder, then delete the statement below and remove the if condition
reminder = "";
if(curr_len>10){
rem_len = max_len - curr_len;
reminder = rem_len + "/20 characters remaining";
}
document.querySelector("#char_reminder").innerText = reminder;
}
});