<script type="text/javascript">
var maxLength=160;
var Ascii=true;
function isAscii(el) {
var i=0;
while ( i < el.value.length ){
alert(el.value[i]);
if(el.value[i].charCodeAt(0) >= 0 && el.value[i].charCodeAt(0) <= 127 ){
i=i+1;
}
else
{
return false
}
}
return true;
}
function characterCount(el) {
if ( isAscii(el)){
Ascii=true;
maxLength=160;
}
else {
alert("non-ascii");
Ascii=false
maxLength=70;
}
return true;
}
</script>
<body>
<textarea name='text' onKeyUp='characterCount(this)' id='textarea' cols='60' > </textarea>
</body>
above code alerts for ascii non-ascii characters, I found no point in changing the length of text box on length, but anyways hope you can do that now.
changes in code:
1) el.value[i].charCodeAt(0) -> .(dot) is missing
2) while ( i < el.value.length ){
in above statement you have used <= which was again wrong.