CoderZone.org

Category: >> JavaScript >> Capitalize first letter of words Bookmark and Share

<< lastnext >>

Snippet Name: Capitalize first letter of words

Description: Capitalize the first letter of every word entered into a form field.

Comment: (none)

Author: CoderZone
Language: JAVASCRIPT
Highlight Mode: JAVASCRIPT
Last Modified: February 27th, 2009

<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>
 
<FORM NAME="TEST">
        <INPUT TYPE="TEXT" NAME="TESTER" onChange="capitalizeMe(this)">
</FORM> 
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 3