Title Case on field element

mediaateam

Administrator
I need to force the text in a field to be Title Case. I saw an old forum posting about using js inline on change for all upper case, so I tried the same for this, but it didn't work.

Here's what I have on the Javascript on the field element:

The js is set to work "on change"
Code:
this.value=this.value.toTitleCase();

It doesn't seem to be working. Anyone have a better solution?
 
Good guess but no, there is no native toTtitleCase in Javascript. And it's actually not as simple as you might think, depending how persnickety you want to get. Like, do you need to support names like O'Brian, or McDonald, or Billy-Bob. Do you want to leave "short words" (and, in, of, the, to, etc) un-cased?

Here's one of the best Stack Overflow discussions and a variety of solutions:

http://stackoverflow.com/questions/196972/convert-string-to-title-case-with-javascript/196991#196991

So decide which approach you need to go with, and I'll help you get it going.

-- hugh
 
Is it for display or storing in DB?
It's also possible to use CSS (text-transform: capitalize; ) or php (ucwords (), e.g. in a php validation with replace)
 
I'm assuming she'll want it stored that way, and will want to handle some of those special cases like hyphens and quotes.

Sent from my HTC6500LVW using Tapatalk
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top