“Capitalise” jquery extension

by Evgeny Petrov on December 16th, 2009 | Posted in Revium Sandbox | Read the comments

Sometimes there is a requirement to capitalise certain text input elements in web forms, i.e. to make just the first symbol uppercase when the user inputs details. This is often useful in fields like “first name”, “last name” etc.

The code to handle this is an extremely simple one, but I thought I may share my implementation here with you and save you some precious time. Here it is:

//
// Revium jquery extensions
// Copyright (c) 2009 Revium pty ltd http://revium.com.au
// Licensed under the GPL licence:
// http://www.gnu.org/licenses/gpl.html
//

(function($) {
    // To capitalise text input when user types in (to make just the 1st symbol uppercase)
    // Developed by Evgeny Petrov, Revium
    // Ver 1.0, 24/11/2009
    $.fn.capitalise = function() {
        $(this).keyup(function() {
            var el = $(this);
            var value = "";
            if (el.length > 0) {
                value = el.val().toString().substr(0, 1).toUpperCase() + el.val().toString().substr(1);
            }
            el.val(value);
        });
    }
})(jQuery);

This is how you may use it (all inputs with class “capitalise” will be capitalised):


Enjoy!

Update

I was just advised that the same may be easily achieved by using pure css. Fair enough – 2 options are better than none! :-)

input { text-transform: capitalize; }

Please be aware though that the css option doesn’t actually change the text, it just shows it capitalised. So when you submit your form, your inputs will not be capitalised.

Related posts:

  1. ASP.NET selectors in jquery
  2. jQuery image captions
  3. ASP.NET Button – prevent double clicks part 2
  4. Power of the ASP.NET MVC + jquery
  5. Developing faster web forms in .NET

Tags: jquery

« Email source code in MS Outlook

Sharepoint Web Part Grouping »

One Response to ““Capitalise” jquery extension”

  1. b says:
    January 4, 2010 at 5:12 pm

    we like to call that… Title Case

Leave a Reply

Click here to cancel reply.

Recent Articles

  • 10 Tips for user acceptance testing of web applications
  • Popular Content Management Systems
  • ASP.NET MVC [HandleError] and logging
  • VMWare hard lessons
  • Linq – SubmitChanges does not work
  • Using FourSquare for Marketing
  • ASP.NET Button – prevent double clicks part 2
  • The easy way to clear floated elements

Twitter

  • 50 Useful Tools & Resources For Web Designers <http://www.smashingmagazine.com/2010/07/26/50-useful-tools-and-resources-for-web-designers/> 3 days ago
  • Tourism Australia has launched a free "Go Ashes" app for iPhone to promote England vs Australia cricket series 4 days ago
  • #YouTube competition, on 24 July capture you Life In A Day http://youtu.be/tZFbDY3-eG4 1 week ago
  • More updates...

Revium Logo

  • Home
  • About
  • Expertise
  • Showcase
  • Contact

  • news
  • blog
  • sandbox
  • twitter
  • facebook
  • rss
Bookmark and Share

We are Revium, hear us roar!

The news.

23 Apr

Revium sponsors IIA CEO luncheon on 2010 Challenges

Last Wednesday 14th April Revium hosted a CEO luncheon for the Internet Industry Association (IIA). Revium have been long time supporters of the IIA and…

Continue reading
View archive

The blog.

11 Jun

VMWare hard lessons

Well, I learned a hard lesson today when I decided to give more hard drive space to one of our virtual machines. We run…

Continue reading
View archive

The sandbox.

02 Jul

10 Tips for user acceptance testing of web applications

1. Draw up a testplan Many testers would like to skip this step, but it is essential for structured testing. It depends of course on the…

Continue reading
View archive

eNewsletter.

 

© Copyright 2010. All Rights Reserved.

Revium Pty Ltd

e / info@revium.com.au t / Work +61 3 9429 2000

Find us: web development, seo

Disclaimer and privacy Revium Pty Ltd

10 Harvey Street
Richmond, Victoria, 3121 Australia
View map

Logo Partner MicrosoftLogo Partner KenticoLogo Partner IiaLogo Partner Iia RibLogo Partner Acs