initCap for JavaScript
Just posting this to have it in my code snippets :-) Javascript function to capitalize the first letter of a phrase or word....
<script type="text/javascript">
function initCap(str) {
/* First letter as uppercase, rest lower */
var str = str.substring(0,1).toUpperCase() + str.substring(1,str.length).toLowerCase();
return str;
}
</script>
<input type="text" value="chANGE this PHrase!" name="field1">
<input type="button" onclick="alert(initCap(field1.value))" value="Test initCap">
10931 viewed | 3 opinion(s) | del.icio.us | Digg it | Tjarko @ 03/03/06 11:31 cet



