Full version: jsB@nk » Form » Converting a String to Title/Sentence Case
URL: https://www.javascriptbank.com/converting-a-string-to-title-sentence-case.html
This JavaScript helps you to convert a set of words to sentence case or title case. Ugly but quick JavaScript to convert a given sentence to title case.
Full version: jsB@nk » Form » Converting a String to Title/Sentence Case
URL: https://www.javascriptbank.com/converting-a-string-to-title-sentence-case.html
<SCRIPT language=javascript>function rtrim(strInput) { while (1) { if (strInput.substring(strInput.length - 1, strInput.length) != " ") break; strInput = strInput.substring(0, strInput.length - 1); } return strInput;}function ltrim(strInput) { while (1) { if (strInput.substring(0, 1) != " ") break; strInput = strInput.substring(1, strInput.length); } return strInput;}function trim(strInput) { var tmpstr = ltrim(strInput); return rtrim(tmpstr);}function sentencecase(strInput){strInput = trim(strInput);strInput = ' ' + strInput;strInput=strInput.toLowerCase();var firstcharlc=strInput.charAt(1);var firstcharuc=firstcharlc.toUpperCase();firstcharuc = " " + firstcharuc;firstcharlc = " " + firstcharlc;strInput=strInput.replace(firstcharlc, firstcharuc);strInput=trim(strInput);var len = strInput.length;var spacePos = strInput.indexOf(' ');while (spacePos != -1) {var firstcharlc = strInput.charAt(spacePos+1);var firstcharuc=firstcharlc.toUpperCase();firstcharuc = " " + firstcharuc;firstcharlc = " " + firstcharlc;strInput=strInput.replace(firstcharlc, firstcharuc);strInput=trim(strInput);spacePos = strInput.indexOf(' ',spacePos+1);}return strInput;}</SCRIPT><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->
<FORM name=MYFORM><INPUT name=mySentence> <INPUT onclick="document.MYFORM.mySentence.value = sentencecase(document.MYFORM.mySentence.value);" type=button value="Click Here"> </FORM><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->