Javascript for forcing text response to lowercase | XM Community
Solved

Javascript for forcing text response to lowercase

  • 26 March 2024
  • 2 replies
  • 36 views

Badge

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? 

icon

Best answer by Tom_1842 27 March 2024, 14:29

View original

2 replies

Userlevel 3
Badge +11

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.

 

Userlevel 7
Badge +27

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();
});

 

Leave a Reply