Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

How can you use the 'toProperCase' function on a variable

Tutsaa
Level 1
Level 1

Hi,

 

We would like to use the 'toProperCase' function on the <%= recipient.preferredName %> 

 

But unsure of how to format it? Please could someone help!

 

Thanks,

Tutu

1 Accepted Solution
Manoj_Kumar_
Correct answer by
Community Advisor
Community Advisor

@Tutsaa 

First define the function like this

<%

String.prototype.toProperCase = function() {
var words = this.split(' ');
var results = [];
for (var i = 0; i < words.length; i++) {
var letter = words[i].charAt(0).toUpperCase();
results.push(letter + words[i].slice(1));
}
return results.join(' ');
};

%>

Then you can use it like this 

<%= recipient.preferredName.toProperCase() %>

 

View solution in original post

3 Replies
Manoj_Kumar_
Correct answer by
Community Advisor
Community Advisor

@Tutsaa 

First define the function like this

<%

String.prototype.toProperCase = function() {
var words = this.split(' ');
var results = [];
for (var i = 0; i < words.length; i++) {
var letter = words[i].charAt(0).toUpperCase();
results.push(letter + words[i].slice(1));
}
return results.join(' ');
};

%>

Then you can use it like this 

<%= recipient.preferredName.toProperCase() %>

 

dloyd
Level 4
Level 4

Could also do something like this... (The joy of JavaScript, 1000 ways to do the same thing!)

 

<%​
function nameProper() {​
  var name = recipient.firstName;​
  var propName = name.chartAt(0).toUpperCase() + name.slice(1);​
}%>​

Dear <%= nameProper %>,

 

Dear <%= nameProper %>,

Jyoti_Yadav
Community Advisor
Community Advisor

Hi @Tutsaa ,

 

You can use a simple version also:

<%= recipient.preferredName.substring(0,1).toUpperCase()+ recipient.preferredName.substring(1,100).toLowerCase() %>

 

Thanks,

Jyoti Yadav