@PittimannJul 16.2004 — #Hi!Does anyone have a JavaScript for sentence casing?[/QUOTE]Until today, I didn't have any but I botched one together for you:[code=php]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled</title> <script language="JavaScript" type="text/javascript"> <!-- function sCase(){ val=document.getElementById('original').innerHTML; 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(/[.|?|!]/); for (var j=0;j<val2.length;j++){ var temp=val2[j].split(' '); if(temp.length>1){ 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; } result2+=temp.join(' ')+endSentence[j]; } } document.getElementById('modified').innerHTML=result2; } //--> </script> </head> <body> <div id="original">HOW ARe you TODAY? i'm fine, THANKS! aND You? welL - DUNNO.</div> <div id="modified"> </div> <a href="#" onclick="sCase()">Arrange cases</a> </body> </html>[/code]The function will recognize full stops, question marks and exclamation marks as the end of a sentence.
Cheers - Pit
Edit: I just view the stuff in Mozilla for fun (not expecting any problems) and found, Mozilla couldn't handle the code. So I modified it to overcome that bug.