Solved

Making first letter of the text uppercase

Posted on 2011-09-20
9
370 Views
Last Modified: 2012-05-12
I have textboxes for data entry. What is the javascript function to make first letter of the text as Uppercase with the rest normally entered as lowercase.
0
Comment
Question by:zachvaldez
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 13

Accepted Solution

by:
ansudhindra earned 50 total points
ID: 36568631
you can use this function

function capitaliseFirstLetter(string)
{
    return string.charAt(0).toUpperCase() + string.slice(1);
}

Sudhindra - www.clicksperday.com
0
 
LVL 9

Assisted Solution

by:sshah254
sshah254 earned 50 total points
ID: 36568640
Try this:

http://stackoverflow.com/questions/196972/convert-string-to-proper-case-with-javascript

function toTitleCase(str)
{
    return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}

SS
0
 
LVL 16

Assisted Solution

by:disrupt
disrupt earned 100 total points
ID: 36568694
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 51

Assisted Solution

by:Huseyin KAHRAMAN
Huseyin KAHRAMAN earned 50 total points
ID: 36568698
maybe this help...

(not functioning correctly if you have text, select all and press a new key, which replaces all)
<script>
function up(t, e){
  if (!e) var e = window.event;//alert(e.keyCode);
  if (t.value=="") e.keyCode = (e.keyCode>=97 && e.keyCode<=122)?e.keyCode-32:e.keyCode;
}
</script>

<input id=txt onKeyPress="up(this, event)">

Open in new window

0
 

Author Comment

by:zachvaldez
ID: 36568894
on what event is this use /added as property/funciton in the source?
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36568903
on blur event
0
 
LVL 16

Assisted Solution

by:disrupt
disrupt earned 100 total points
ID: 36569049
check this out:

  <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('#<%= TextBox1.ClientID %>').blur(function() {
        $("#<%= TextBox1.ClientID %>").val(capitalize($(this).val()));
        });

        function capitalize(a) {
            newVal = '';
            a = a.split(' ');
            for (var c = 0; c < a.length; c++) {
                newVal += a[c].substring(0, 1).toUpperCase() + a[c].substring(1, a[c].length) + ' '
            }
            return newVal
        }
    });
</script>

Open in new window

0
 

Author Closing Comment

by:zachvaldez
ID: 36570211
too many answers,too little points to spread.Thanks guys
0
 

Author Closing Comment

by:zachvaldez
ID: 36570213
too many answers,too little points to spread.Thanks guys
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question