Jump to content


Photo

Capitalize 1st Character only


  • Please log in to reply
3 replies to this topic

#1 gabe8496

gabe8496
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 08 May 2006 - 04:55 PM

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:

<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>

So, in the end...if the user types SAN BENITO, TEXAS, I want it to change to => San Benito, Texas

I'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

#2 lead2gold

lead2gold
  • Members
  • PipPipPip
  • Advanced Member
  • 164 posts
  • LocationOttawa, On

Posted 08 May 2006 - 04:58 PM

$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


#3 gabe8496

gabe8496
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 08 May 2006 - 05:02 PM

[!--quoteo(post=372320:date=May 8 2006, 11:58 AM:name=lead2gold)--][div class=\'quotetop\']QUOTE(lead2gold @ May 8 2006, 11:58 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
$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
[/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, texas
Field updates to: San Benito, Texas

This is perfect...but

If the user does the following:
User types: SAN BENITO, TEXAS
Form Field updates to: SAN BENITO, TEXAS

As 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

#4 lead2gold

lead2gold
  • Members
  • PipPipPip
  • Advanced Member
  • 164 posts
  • LocationOttawa, On

Posted 08 May 2006 - 05:05 PM

Ok, do this then:
$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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users