gabe8496 Posted May 8, 2006 Share Posted May 8, 2006 I use a text field to allow a user to specify custom text and on submit, it generates a image with embedded text.Right now, i'm getting it to uppercase all 1st letter of each word...HOWEVER, I have some issues where a customer can have their caps lock and all their text is set to uppercase, which is a problem. Here is teh script I'm using right now:[code]<script LANGUAGE="JAVASCRIPT"><!--function capitalizeMe(obj) { val = obj.value; newVal = ''; val = val.split(' '); for(var c=0; c < val.length; c++) { newVal += val[c].substring(0,1).toUpperCase() +val[c].substring(1,val[c].length) + ' '; } obj.value = newVal;}// --></SCRIPT>[/code]So, in the end...if the user types SAN BENITO, TEXAS, I want it to change to => San Benito, TexasI'm not all that familiar with javascript, so if anyone can help me out and explain how it works, I would greatly appreciate it.Thanks!Gabe Quote Link to comment Share on other sites More sharing options...
lead2gold Posted May 8, 2006 Share Posted May 8, 2006 [code]$str = "Mary Had A Little Lamb and She LOVED It So";$str = ucfirst(strtolower($str));echo $str; // Prints: Mary had a little lamb and she loved it so[/code] Quote Link to comment Share on other sites More sharing options...
gabe8496 Posted May 8, 2006 Author Share Posted May 8, 2006 [!--quoteo(post=372320:date=May 8 2006, 11:58 AM:name=lead2gold)--][div class=\'quotetop\']QUOTE(lead2gold @ May 8 2006, 11:58 AM) [snapback]372320[/snapback][/div][div class=\'quotemain\'][!--quotec--][code]$str = "Mary Had A Little Lamb and She LOVED It So";$str = ucfirst(strtolower($str));echo $str; // Prints: Mary had a little lamb and she loved it so[/code][/quote]Thanks for that info.However, I don't think that would work in my situation.How it works right now:User types: san benito, texasField updates to: San Benito, TexasThis is perfect...butIf the user does the following:User types: SAN BENITO, TEXASForm Field updates to: SAN BENITO, TEXASAs you can see, the field stays in all caps. I would need the output (if the user types all caps) to go to => San Benito, Texas Quote Link to comment Share on other sites More sharing options...
lead2gold Posted May 8, 2006 Share Posted May 8, 2006 Ok, do this then:[code]$str = "Mary Had A Little Lamb and She LOVED It So";$str = ucwords(strtolower($str));echo $str; // Prints: Mary Had A Little Lamb And She Loved It So[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.