Capitalize all letters in the text-box | XM Community
Solved

Capitalize all letters in the text-box


Badge

I am trying to capitalize all the letters in the text box as the respondent types. Is there a way of doing that? Thank you.

icon

Best answer by rondev 5 April 2020, 13:44

View original

12 replies

Userlevel 7
Badge +22

Use the below code
jQuery(".InputText").css("text-transform","uppercase");

Userlevel 7
Badge +27

That will make the input appear in uppercase but it won't store it as uppercase. To do that, you need:
jQuery("#"+this.questionId+" .InputText").on("input", function() { this.value = this.value.toUpperCase(); });

Badge

Thanks a lot! This works. I really appreciate your response. I am going to be piping the text, and want the piped text to be in uppercase too. This saves me having to code further.

Badge +9

TomG me again! How would this code differ if applying to a matrix table?

Userlevel 7
Badge +27

How would this code differ if applying to a matrix table?

Change the last part of the selector to " td input[type=text]"

Badge +9

Thank you, TomG !!

Hi TomG that line doesn't seem to be working for me and I'm wondering if the existing code has something to do with it. Where would I put it within the following?
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();
});
Edit: never mind I figured it out - it needed to go before the cursor line in the OnReady function

Userlevel 2
Badge +3

TomG what about converting to capital first letter, lower case for the rest? Thanks

Userlevel 7
Badge +27

https://community.qualtrics.com/XMcommunity/discussion/comment/42098#Comment_42098There isn't an equivalent toUpperCase() JS function for proper (aka title) case. You could create your own function utilizing regex.

Userlevel 2
Badge +10

TomG Your code works beautifully for text entry and form field questions. However, I have a situation where I only need one field of a multi-field Form Fields question type to be capitalized. I've been trying to figure out how to modify your code to apply to only to that one specific field, but haven't been successful. Would you mind providing an example of how that would be done? In my case, the field I'm trying to reference is ${q://QID5/ChoiceTextEntryValue/3} and I'm applying the js to the question itself.
I've been able to solve the problem by using an embedded data placeholder and the below js applied to a later question, but your approach is much more elegant and I would like to learn how to apply it to this particular situation. Thank you in advance!
var other_ID = "${q://QID5/ChoiceTextEntryValue/3}".toUpperCase();
Qualtrics.SurveyEngine.setEmbeddedData("other_ID", other_ID);

Userlevel 7
Badge +27

https://community.qualtrics.com/XMcommunity/discussion/comment/45075#Comment_45075jQuery("#"+this.questionId+" .InputText").eq(2).on("input", function() { this.value = this.value.toUpperCase(); });
The above will only apply to the third text input in the question (indices start at 0).

Userlevel 2
Badge +10

https://community.qualtrics.com/XMcommunity/discussion/comment/45076#Comment_45076TomG Thank you SO much for the fast reply and the reminder about indices! That worked perfectly. I see you all over these boards and always learn a lot from your answers. 🙏

Leave a Reply