Complete code:
<script language= "JavaScript" > <!--Begin function ChangeCase (frmobj) {var index; var tmpstr; var Tmpchar; var prestring; var poststring; var strlen; Tmpstr = FrmObj.value.toLowerCase (); StrLen = Tmpstr.length; if (StrLen > 0) {for (index = 0; index < strLen; index++) {if (index = = 0) {Tmpchar = tmpstr.substring (0,1). To Uppercase (); poststring = tmpstr.substring (1,strlen); TMPSTR = Tmpchar + poststring; else {Tmpchar = tmpstr.substring (index, index+1); if (Tmpchar = = "" && Index < (strLen-1)) {Tmpchar = tmp Str.substring (index+1, index+2). toUpperCase (); prestring = tmpstr.substring (0, index+1); poststring = tmpstr.substring (Index+2,strlen); TMPSTR = prestring + Tmpchar + poststring; }}} Frmobj.value = Tmpstr; }//End--> </script> <form name=form> <input type=text name=box value= ' type in here! ' > <input type=button value= "Convert" onclick= "Javascript:changecase (this.form.box)" > </form>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
Script Description:
The first step: Add the following code to the <script language= "JavaScript" >
<!--Begin
function ChangeCase (frmobj) {
var index;
var tmpstr;
var Tmpchar;
var prestring;
var poststring;
var strlen;
Tmpstr = FrmObj.value.toLowerCase ();
StrLen = Tmpstr.length;
if (StrLen > 0) {
for (index = 0; index < strLen; index++) {
if (index = = 0) {
Tmpchar = tmpstr.substring (0,1). toUpperCase ();
poststring = tmpstr.substring (1,strlen);
TMPSTR = Tmpchar + poststring;
}
else {
Tmpchar = tmpstr.substring (index, index+1);
if (Tmpchar = = "" && Index < (strLen-1)) {
Tmpchar = tmpstr.substring (index+1, index+2). toUpperCase ();
prestring = tmpstr.substring (0, index+1);
poststring = tmpstr.substring (Index+2,strlen);
TMPSTR = prestring + Tmpchar + poststring;
}
}
}
}
Frmobj.value = TMPSTR;
}
End-->
</script>
Step Two: Add the following code to the <body> area
<form name=form>
<input type=text name=box value= "type in here!" >
<input Type=button value= "Convert" onclick= "Javascript:changecase (this.form.box)" >
</form>