Home
Developer Blog
Ajax effects
CSS examples
Freelance jobs
Hot IT Jobs
Hot scripts
Code samples
Web hosting directory
Lotus Notes FAQ
See the new scripts recently added to Dynamic Drive.
Click here
.
Original, practical
CSS codes and examples
such as CSS menus for your site.
Search code samples
Keyword
All Categories
ASP
CSS
Dhtml
Html
Javascript
PHP
Code Samples
ASP
CSS
Dhtml
Html
Javascript
PHP
LOGIN HERE
Username
Password
Signup Now
Forgot Password
Verify Signup
Javascript >> General
How can I capitalise the first letter of every word ?
Visitor Ratings (1) :
Description
Try the following code.
Code
Select All
<html> <head> <script language="JavaScript1.2"><!-- function toUpper() { var pattern = /(\w)(\w*)/; // a letter, and then one, none or more letters var a = document.form1.text1.value.split(/\s+/g); // split the sentence into an array of words for (i = 0 ; i < a.length ; i ++ ) { var parts = a[i].match(pattern); // just a temp variable to store the fragments in. var firstLetter = parts[1].toUpperCase(); var restOfWord = parts[2].toLowerCase(); a[i] = firstLetter + restOfWord; // re-assign it back to the array and move on } document.form1.text1.value = a.join(' '); // join it back together } //--></script> </head> <body> <form name="form1"> <input type="text" name="text1"> <input type="button" onClick="toUpper()" value="To Upper Case"> </form> </body> </html>
Rate this Resource
0
1
2
3
4
5
6
7
8
9
10