<html>
<head>
<script language="JavaScript" type="text/javascript">
function ConvertToLetterCase(frmObj) {
var i;
var tmpStr;
var tmpChar;
var preString;
var postString;
var strlen;
tmpStr = frmObj.value.toLowerCase();
strLen = tmpStr.length;
if (strLen > 0) {
for (i = 0; i < strLen; i++) {
if (i == 0) {
tmpChar = tmpStr.substring(0,1).toUpperCase();
postString = tmpStr.substring(1,strLen);
tmpStr = tmpChar + postString;
}
else {
tmpChar = tmpStr.substring(i, i+1);
if (tmpChar == " " && i < (strLen-1)) {
tmpChar = tmpStr.substring(i+1, i+2).toUpperCase();
preString = tmpStr.substring(0, i+1);
postString = tmpStr.substring(i+2,strLen);
tmpStr = preString + tmpChar + postString;
}
}
}
}
frmObj.value = tmpStr;
}
</script>
</head>
<body>
<center>
Convert First Letter In Each Word To Capitalize Using Javascript<br/>
<form name="caseConvert">
<textarea name="txt_content" cols="40" rows="5">any LeTTer that you WILL wRiTe heRe will BE CapitaLiZed.
</textarea><br/><br/>
<input type=button value="Initialize Capitalized"onClick="javascript: ConvertToLetterCase(this.form.txt_content);">
</form>
</center>
</body>
</html>
Thursday, January 29, 2009
Capitalize every words using JavaScript
Save the below text in a text file and save it as html and then open it with any browser where javascript is enabled.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment