Solved

Making first letter of the text uppercase

Posted on 2011-09-20
9
368 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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
 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
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 receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

809 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