Solved

Making first letter of the text uppercase

Posted on 2011-09-20
9
371 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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
LVL 55

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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Find out what you should include to make the best professional email signature for your organization.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

724 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