Tuesday, 24 November 2009

How to get letters uppercased directly in XHTML form with JavaScript

Welcome again!

The thing I will be talking about is how to control letters in HTML forms. Click here for the example.

I've recently been working on a small project and surprisingly I needed to do something, what I have never faced before. What we will be talking about this time, is how to control letters in HTML forms, for example:
you might have just launched a website with a contact form where visitors leave their name. You know that a lot of people think differently and what they think "name" stands for is different too. So, one person might enter his name as "John Smith", the other one as:"joHn SMith". We all see the difference and if you need this kind of information to be official and standart, you need to make a filter which would re-create the names written and send them to the server in an apropriate form ( like "John Smith" with the first letters uppercassed).
So in this post I will tell you how I have handeled this kind of situation. To make this kind of filter I have used two main functions in Javascript:
  • split();
  • substring();
Here is the full screenshot of the function in the"head" section:







( click for a larger view)

You can read the comments in the source code to understand the code better. I've also found a great tutorial page for this particular lesson here. Feel free to test this code here.

Hope, I helped you a bit, 'couse to me it all took a while since I haven't been doing anything related to this. Keep reading!

Cheers, A


No comments:

Post a Comment