Click to See Complete Forum and Search --> : uCase, lCase ???
Danbabe
03-24-2005, 01:16 PM
I know all about uCase for converting strings to upper case and lCase accordingly but... How can I convert a string to Title Case capitalising the first letter only of a string?
My members are completing their addresses on my site but people don't seem too bothered how it looks, everything is in lower case, including towns and cities.
If you can help, then thanks.
Happy Easter everyone
Dan
lmf232s
03-24-2005, 01:33 PM
you can do this with javascript. Here is the script but this will
cap the whole string.
What you need to do is get the first value of the string and cap it
but this is kind of the jist
I have this firing everytime on the Keyup, you could just fire the sub when the onChange event triggers.
function capMe(obj){
var who = document.getElementById(obj).value;
document.getElementById(obj).value = who.toUpperCase(who);
}
<input type=text name=txtState size=2 maxlength=2 ID=State onKeyUp="capMe('State');">
phpnovice
03-24-2005, 04:43 PM
Originally posted by Danbabe
How can I convert a string to Title Case capitalising the first letter only of a string?
I wrote a VBScript function to do that -- but it is at home. I'll post it this evening. This function capitalizes the first character of each word in the string.
Danbabe
03-24-2005, 07:10 PM
That would be great if you do have the the code. I look forward to receiving your reply.
Many thanks
Dan
phpnovice
03-24-2005, 07:15 PM
Well, I got home and found that I had written it in Visual Basic -- not VBScript. So, I converted it but it is untested now. At any rate, the second argument is a Boolean value specifying whether ALL words should be processed or not. The default is True but, if False, only the first word is processed.
<%
Function WordCaps(ByVal str1, ByVal all)
Dim idx, ary1
If IsEmpty(all) Then all = True
ary1 = Split(LTrim(LCase(str1)), " ")
For idx = LBound(ary1) To UBound(ary1)
If Len(ary1(idx)) > 0 Then
Mid(ary1(idx), 1, 1) = UCase(Mid(ary1(idx), 1, 1))
End If
If Not all Then Exit For
Next
WordCaps = Join(ary1, " ")
End Function
%>
Danbabe
03-24-2005, 07:26 PM
Jees, that's a bit beyond me to comprehend. I don't suppose you could break that down for me by any chance? If you want to post a direct reply, then email me at danny@fastsites.co.uk.
Thank you for your help
Regards
Dan
phpnovice
03-24-2005, 07:31 PM
He, he, he... Why do you have to comprehend it? Just use it and enjoy. :D
By the way, I edited it a bit -- in hopes of making it more inline with VBScript standards.