I am just posting a Javascript sample which I created for answering a question in dotnetspider.
<html>
<head>
<title>Proper Case Validation -- Sample by Vadivel</title>
<script>
<!--
function ConvertToProperCase()
{
strTemp = document.form1.txtString.value
strTemp = strTemp.toLowerCase()
var test=""
var isFirstCharOfWord = 1
for (var intCount = 0; intCount < strTemp.length; intCount++)
{
var temp = strTemp.charAt(intCount)
if (isFirstCharOfWord == 1)
{
temp = temp.toUpperCase()
}
test = test + temp
if (temp == " ")
{
isFirstCharOfWord = 1
}
else isFirstCharOfWord = 0
}
document.form1.txtString.value = test
}
// -->
</script>
</head>
<body>
<form name=form1>
<input size=50 name=txtString>
<input type=button onClick=ConvertToProperCase() value="Convert It Now">
</form>
</body>
</html>
Update: I have tested it with IE 6.0 alone. May be for working in other browsers you need to do little bit of tweaking. For ex: need to put semi-colons at the end of each statements.
<html>
<head>
<title>Proper Case Validation -- Sample by Vadivel</title>
<script>
<!--
function ConvertToProperCase()
{
strTemp = document.form1.txtString.value
strTemp = strTemp.toLowerCase()
var test=""
var isFirstCharOfWord = 1
for (var intCount = 0; intCount < strTemp.length; intCount++)
{
var temp = strTemp.charAt(intCount)
if (isFirstCharOfWord == 1)
{
temp = temp.toUpperCase()
}
test = test + temp
if (temp == " ")
{
isFirstCharOfWord = 1
}
else isFirstCharOfWord = 0
}
document.form1.txtString.value = test
}
// -->
</script>
</head>
<body>
<form name=form1>
<input size=50 name=txtString>
<input type=button onClick=ConvertToProperCase() value="Convert It Now">
</form>
</body>
</html>
Update: I have tested it with IE 6.0 alone. May be for working in other browsers you need to do little bit of tweaking. For ex: need to put semi-colons at the end of each statements.
Comments
function ConvertToProperCase()
{
strTemp = document.form1.txtString.value;
strTemp = strTemp.toLowerCase();
var test="";
var isFirstCharOfWord = 1;
for (var intCount = 0; intCount < strTemp.length; intCount++)
{
var temp = strTemp.charAt(intCount);
if (isFirstCharOfWord == 1)
{
temp = temp.toUpperCase();
}
test = test + temp;
if (temp == " ")
{
isFirstCharOfWord = 1;
}
else
{
isFirstCharOfWord = 0;
}
}
document.form1.txtString.value = test;
}