-4

Using JavaScript in ASP.NET, I need to convert lowercase letters into uppercase letters.

How can I solve this problem with correct answer in JavaScript?

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head id="Head1" runat="server">
<title></title>

<script language="JAVASCRIPT">
     function capitalizeMe(obj) {
         val = obj.value;
            newVal = '';
         val = val.split(' ');
         for (var c = 0; c < val.length; c++) {
             newVal += val[c].substring(0, 1).toUpperCase() +
             val[c].substring(1, val[c].length) + ' ';
         }   
     }
</script>

</head>
<body>
     <form id="Form2" runat="server">
        <asp:TextBox ID="TextBox1" runat="server" onblur="capitalizeMe(this)">
        </asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
     </form> 
  </body>
</html>
kojiro
  • 74,557
  • 19
  • 143
  • 201
  • please search on SO before posting: dupplicate of http://stackoverflow.com/questions/1026069/capitalize-the-first-letter-of-string-in-javascript – Frederik.L Apr 12 '13 at 11:15

2 Answers2

3

Why dont you use css instead?

.capitalized{
    text-transform: capitalize
}

Add the class to your elements and have css handle the rest

Dogoku
  • 4,585
  • 3
  • 24
  • 34
0
 <script language="JAVASCRIPT">
 function capitalizeMe(obj) {
    val = obj.value;
        newVal = '';
     val = val.split(' ');
     for (var c = 0; c < val.length; c++) {
    newVal += val[c].substring(0, 1).toUpperCase() +
 val[c].substring(1, val[c].length) + ' ';
  }
    obj.value = newVal;
   }
    </script>
Vikash Chauhan
  • 792
  • 2
  • 9
  • 18