How to capitalise input to a text box? | XM Community
Skip to main content
Solved

How to capitalise input to a text box?

  • March 23, 2021
  • 1 reply
  • 71 views

Hi there, I am trying to have the input of a text box both appear and be stored in uppercase. I found the following line here, however it's not working for me and I wonder if it's clashing with my existing code.
Here's the line I want to integrate:
jQuery("#"+this.questionId+" .InputText").on("input", function() { this.value = this.value.toUpperCase(); });

And here is my existing code:
Qualtrics.SurveyEngine.addOnload(function()  {
//hide next button
this.hideNextButton();
//press enter to go to next question
    document.on("keydown", function(e) {
         if (e.keyCode === 13) $('NextButton').click();
    });
});


Qualtrics.SurveyEngine.addOnReady(function(){
//cursor in text box
$(this.questionId).down('.InputText').focus().defer();
});
Have tried putting the new line in each of the Onload and OnReady functions.
I'm new to javascript so apologies if I'm missing something very obvious

Best answer by rmuoa

Never mind I answered my own question! I will leave it up in case this helps anyone else though - the solution was to put it before the cursor line within the OnReady function, for some reason it did not work if I put it second.
Qualtrics.SurveyEngine.addOnload(function()  {
//hide next button
this.hideNextButton();
//press enter to go to next question
    document.on("keydown", function(e) {
         if (e.keyCode === 13) $('NextButton').click();
    });
});


Qualtrics.SurveyEngine.addOnReady(function(){
//capitalise text entry
jQuery("#"+this.questionId+" .InputText").on("input", function() { this.value = this.value.toUpperCase(); });
//cursor in text box
$(this.questionId).down('.InputText').focus().defer();
});

1 reply

  • Author
  • Answer
  • March 23, 2021

Never mind I answered my own question! I will leave it up in case this helps anyone else though - the solution was to put it before the cursor line within the OnReady function, for some reason it did not work if I put it second.
Qualtrics.SurveyEngine.addOnload(function()  {
//hide next button
this.hideNextButton();
//press enter to go to next question
    document.on("keydown", function(e) {
         if (e.keyCode === 13) $('NextButton').click();
    });
});


Qualtrics.SurveyEngine.addOnReady(function(){
//capitalise text entry
jQuery("#"+this.questionId+" .InputText").on("input", function() { this.value = this.value.toUpperCase(); });
//cursor in text box
$(this.questionId).down('.InputText').focus().defer();
});