Ein kleines JavaScript das automatisch beim Satzanfang einen großen Buschstaben erstellt wenn bei Eingabe kleingeschrieben wird.
Autor: Pittimann
zur Demo
in <head> einfügen
<script type="text/javascript">
<!-- Created by: Pittimann -->
function 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>
in <body> einfügen
<form name="formDemo">
<input size=50 name="convert" onkeyup="sCase()">
</form>
|