Javascript for forcing text response to lowercase | XM Community
Skip to main content

I need to force lowercase a response (participant’s email) collected via text box and save it as lowercase. Any ideas on how to do this? 

Hi @mhiser1024 ,

Add JavaScript to the Survey Flow:
   - Go to the Survey Flow section of your survey.
   - Add a new element and choose "JavaScript."
   - Enter the following JavaScript code:

   ```javascript
   Qualtrics.SurveyEngine.addOnload(function() {
       // Get the input element by its ID
       var emailInput = document.getElementById("yourTextBoxID");

       // Add an event listener to the input element to convert input to lowercase
       emailInput.addEventListener("input", function() {
           this.value = this.value.toLowerCase();
       });
   });
   ```

   Replace `"yourTextBoxID"` with the actual ID of the text box where participants enter their email.

 


In the Survey Flow, I do not see an element called "JavaScript". The code looks good though. I’ve edited it to get the ID of the Text Entry question. Try adding the below to the OnReady section of the Text Entry question's JavaScript to force lower case.

var emailInput = document.getElementById("QR~"+this.questionId);
emailInput.addEventListener("input", function() {
this.value = this.value.toLowerCase();
});

 


Hello to all

Can you help me with this...
I added the code in the javascript in one of the questions in my survey, to force the use of lowercase in a text input. It works for the Preview of the survey, but as we send the survey by api, it does not work....

Does anyone know what is the reason?

Thanks

 


I found the error… thank!


Hi @Tom_1842 

I wanted to ask you, I need the customer to leave a Comment as he wants, writing in uppercase or lowercase, but when it is saved in Qualtrcis, it must be saved in lowercase....

To do this I must add the following code in the javascript part of the addOnUnload

 

is this correct?


Leave a Reply