Hi Qualtrics Community,
I am writing to seek assistance with developing a Java Script code for a survey that I have created. I have to score a text entry and I need the answer to be scored taking case-sensitivity into account ("Wr12" would be correct, but "wr12" would not be). From this previous thread I understand that Qualtrics is case insensitive and that the solution is to develop a Java Script. (https://community.qualtrics.com/XMcommunity/discussion/5151/case-sensitive-scoring-validation-for-a-text-entry-question).
Unfortunately, it is my first time using a Java Script and was hoping that a colleague in this forum could assist me in creating a script I could implement.
Thank you in advance. Please let me know if you require any additional information.
Hi all,
I have the same problem and I know the solution on Javascript (and you can text it here in this online compiler) but it still does not work on Qualtrics (i.e. Qualtrics validates TRUE ab == Ab, while JavaScript doesn't)
I post here the code for your reference:
Qualtrics.SurveyEngine.addOnload(function()
{
let text1 = "${q://QID182/QuestionText}";
let text2 = "RsRs";
let result = text1 == text2
if (result == true) {
var score = 1;
} else if (result == false) {
var score = 0;
}
Can anyone suggest a workaround to solve this?
Thank you very much!
hi all,
I just modified your example slightly and it worked perfectly fine
I created a text entry question and evaluated the entry on PageSubmit
the string I compared against is stored in the embedded data field text3
Qualtrics.SurveyEngine.addOnPageSubmit(function(){
let solution = "${e://Field/text3}"
let textEntry = document.getElementById('QR~'+this.questionId).value
let score;
console.log(textEntry)
if(solution === textEntry){
score = 1
}else{
score = 0
}
let text2 = Qualtrics.SurveyEngine.setEmbeddedData("score", score)
});
best regards
Rudi
Hi Rudi!
Thank you very much for your help! Your solution works perfectly! I just tried to copy and paste this into different questions (all in the same page), and I would need to calculate a total score which is the sum of all scores. How is the correct way to do this? In the meantime I tried to implement this code (but does not work)
I copy this javascript in question1
Qualtrics.SurveyEngine.addOnPageSubmit(function(){
let solution = "${e://Field/text3}"
let textEntry = document.getElementById('QR~'+this.questionId).value
let score1;
console.log(textEntry)
if(solution === textEntry){
score1 = 1
}else{
score1 = 0
}
let text1 = Qualtrics.SurveyEngine.setEmbeddedData("score1", score1)
and this javascript in question2
Qualtrics.SurveyEngine.addOnPageSubmit(function(){
let solution = "${e://Field/text3}"
let textEntry = document.getElementById('QR~'+this.questionId).value
let score2;
console.log(textEntry)
if(solution === textEntry){
score2 = 1
}else{
score2 = 0
}
let text2 = Qualtrics.SurveyEngine.setEmbeddedData("score2", score2)
let score_sum = score1 + score2
let score_sum = Qualtrics.SurveyEngine.setEmbeddedData("score_sum", score_sum)
});
What should I change? Thank you very much again!
Hi Gaiag2 for your score you could do the following, assuming you are calculating it right after you evaluated the second input
let score1 = Qualtrics.SurveyEngine.getEmbeddedData("score1")
let totalScore = Number(score1) + Number(score2)
let score1 = Qualtrics.SurveyEngine.setEmbeddedData("totalScore", totalScore)
Best regards
Rudi
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.