Capitalizing the First Letter in Each Word of a String : String : Language Basics JAVASCRIPT DHTML TUTORIALS


JAVASCRIPT DHTML TUTORIALS » Language Basics » String »

 

Capitalizing the First Letter in Each Word of a String



<html>
<head>
<script language="JavaScript" type="text/javascript">
function capWords(str){ 
   var words = str.split(" ")
   for (var i=; i < words.length ; i++){ 
      var testwd = words[i]
      var firLet = testwd.substr(0,1)
      var rest = testwd.substr(1, testwd.length -1
      words[i= firLet.toUpperCase() + rest 
   
   document.writewords.join(" "))

</script>
</head>
<body>
<script language="JavaScript" type="text/javascript">
capWords("This is a test.");

</script>
</body>
</html>
           
       



-

Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

JAVASCRIPT DHTML TUTORIALS

 Navioo Language Basics
» String