Solved

Making first letter of the text uppercase

Posted on 2011-09-20
9
367 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
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
 
LVL 51

Assisted Solution

by:HainKurt
HainKurt 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

747 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now