Full version: jsB@nk » Form » Proper Format Sentence Submission
URL: https://www.javascriptbank.com/proper-format-sentence-submission.html
Use this JavaScript to make sentence words that users enter correctly, meaning the beginning of each sentence is capitalized, the rest of the sentence is lower case, if they are not proper noun. Let enter some word sentences, sentence examples to test it.
Full version: jsB@nk » Form » Proper Format Sentence Submission
URL: https://www.javascriptbank.com/proper-format-sentence-submission.html
<script type="text/javascript"><!--// Created by: Pittimann :: http://www.webdeveloper.com/forum/showthread.php?t=41676function sCase(){ val=document.formDemo.convert.value; result=new Array(); result2=''; count=0; endSentence=new Array(); for (var i=1;i<val.length;i++){ if(val.charAt(i)=='.'||val.charAt(i)=='!'||val.charAt(i)=='?'){ endSentence[count]=val.charAt(i); count++ }}var val2=val.split(/[.|?|!]/);if(val2[val2.length-1]=='')val2.length=val2.length-1;for (var j=0;j<val2.length;j++){ val3=val2[j];if(val3.substring(0,1)!=' ')val2[j]=' '+val2[j];var temp=val2[j].split(' ');var incr=0;if(temp[0]==''){ incr=1;}temp2=temp[incr].substring(0,1);temp3=temp[incr].substring(1,temp[incr].length);temp2=temp2.toUpperCase();temp3=temp3.toLowerCase();temp[incr]=temp2+temp3;for (var i=incr+1;i<temp.length;i++){ temp2=temp[i].substring(0,1); temp2=temp2.toLowerCase(); temp3=temp[i].substring(1,temp[i].length); temp3=temp3.toLowerCase(); temp[i]=temp2+temp3;}if(endSentence[j]==undefined)endSentence[j]=''; result2+=temp.join(' ')+endSentence[j];}if(result2.substring(0,1)==' ')result2=result2.substring(1,result2.length); document.formDemo.convert.value=result2;}//--></script>
<form name="formDemo"> <input size="50" name="convert" onkeyup="sCase()"></form>