Jump to content

Archived

This topic is now archived and is closed to further replies.

gabe8496

Capitalize 1st Character only

Recommended Posts

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

Share this post


Link to post
Share on other sites
[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]

Share this post


Link to post
Share on other sites
[!--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, 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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.