Javascript code to convert the answer of a client to lowercase | XM Community
Skip to main content

I wanted to consult you, I need that the client leaves a Comment as he wishes, writing in upper or lower case, but when it is saved in Qualtrcis, it must be saved in lower case....

For this, what is the javascript code that I must add in the addOnUnload section?

I am always in favour keeping the original entries incase something goes wrong, therefore, I wouldn't recommend changing the response, but instead you could save it an an embedded data.

Qualtrics.SurveyEngine.addOnReady(function () {
const quest = this;
const qc = quest.getQuestionContainer();
const nextButton = document.querySelector("#NextButton");

nextButton.addEventListener("mouseenter", function () {
const inputField = qc.querySelector("input");
const lowerCaseAnswer = inputField.value.toLowerCase();
Qualtrics.SurveyEngine.setEmbeddedData("answer_in_lowercase", lowerCaseAnswer);
});
});

 

Add this JS code to your question and it will store the response in lowercase in the ED answer_in_lowercase


@Aine You can also work with addOnPageSubmit

Qualtrics.SurveyEngine.addOnPageSubmit(function()
{
var q = this.questionId;
var input = document.getElementById('QR~' + q);
var text = input.value;
Qualtrics.SurveyEngine.setEmbeddedData('ED_LOWER_CASE', text.toLowerCase());
});

 


Hi guys

thank you guys for your answers...

I'm sorry if I did something wrong, but I tried the two proposals you made and they don't work for me. 

 

I added the javascript code, I posted and tried with Preview, and it doesn't save the answer in lower case...

 

Did I do something wrong?


@Aine For my suggestion, the text is stored in some embedded data field ED_LOWER_CASE which should be defined in the survey flow before the question block. 

If you really want to change the actual input to lower case so that the answer to the original question is stored in lower case, you would need to do it like this: 

Qualtrics.SurveyEngine.addOnPageSubmit(function()
{
var q = this.questionId;
var input = document.getElementById('QR~' + q);
var text = input.value;
input.value = text.toLowerCase();
Qualtrics.SurveyEngine.setEmbeddedData('ED_LOWER_CASE', text.toLowerCase());
});

With input.value the input is overwritten. So originally, a text like this is entered: 

When the page is confirmed, the input is changed to upper case. Please keep in mind that the survey respondent will also see it in lower case if he navigates back. The code results in the original answer being overwritten but the text also being stored in a separate embedded data field: 

If this still does not work, please provide information on the question type. Are you using something different than text entry?

Best
Christian


Hi @chackbusch 

Thank you Cristian for such a detailed explanation!
But I ask you if I create an embedded data field, can it influence the score that QC makes later. Because I tell you what is the purpose of what I want to do ....

Currently QC is scoring badly many of the comments of the clients that add keywords in capital letters, it adds a negative score to a comment that was positive but in capital letters...
So my idea is to keep the comment in lowercase to check in a while if the punctuation errors decrease...
Anyway this issue has already been raised to QC...


Hi @chackbusch 

ahhh sorry I misunderstood your explanation.
I tried your proposal and it works fine, save the lowercase answer to the comment question, which is the original one, so that QC can do the correct punctuation…

 

Thank you very much!


Leave a Reply