Using JavaScript to set "FIRST NAME" to titleCase "First Name" | XM Community
Skip to main content
Has anyone found a way to fix all caps embedded data, like "NAME", into something like "Name"?



I think this should be doable with piped text, .setEmbeddedData, and a JS expression to convert the piped text to titleCase.



I've tried:



Qualtrics.SurveyEngine.setEmbeddedData('Value_2', titleCase("${e://Field/Value_1")));



But it didn't work. I'm thinking I first need to correct "Value_1" before I can set it to "Value_2.
Hi,



You can define a function for it and set the value accordingly. Please use below code, it's working fine for me.



var name = "${e://Field/Name}"

var name2 = toTitleCase(name);



function toTitleCase(str) {

return str.replace(

/\\w\\S*/g,

function(txt) {

return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();

}

);

}



Qualtrics.SurveyEngine.setEmbeddedData('Name2',name2);
@Yash - You sir, are a scholar and a saint. Works perfectly!

Yash , I am trying to capitalize all the letters in the text box as the respondents type. Is there a way of doing that? Thank you.


Hi ALX, could you please add below code to your javascript block and let me know any difficulty.
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
jQuery(".InputText").bind('keyup', function (e) {
  if (e.which >= 97 && e.which <= 122) {
    var newKey = e.which - 32;
    e.keyCode = newKey;
    e.charCode = newKey;
  }
  jQuery(".InputText").val((jQuery(".InputText").val()).toUpperCase());
});
});


Hi Yash
Is it possible to capitalize all the letters in the text box as the respondents type for a form field question? I need to ask the first name and last name as individual field questions and I'd prefer to use a form field question. Thank you in advance.


https://community.qualtrics.com/XMcommunity/discussion/comment/43138#Comment_43138Yes, use an "input" handler:
jQuery("#"+this.questionId+" .InputText").on("input", function() {
this.value = this.value.toUpperCase();
});


https://community.qualtrics.com/XMcommunity/discussion/comment/43148#Comment_43148Thank you TomG. It's working great. Very much appreciated.


Leave a Reply