Jump to content

Capitalize 1st Character only


gabe8496

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.