<script>
//################################################
// getByteLength(obj) : 글자수(Byte) 구하기
//################################################
function getByteLength(obj){
var s = obj.value;
var len = 0;
if ( s == null ) return true;
for(var i=0;i<s.length;i++){
var c = escape(s.charAt(i));
if ( c.length == 1 ) len ++;
else if ( c.indexOf("%u") != -1 ) len += 2;
else if ( c.indexOf("%") != -1 ) len += c.length/3;
if(len >= 300 ){
alert("300byte이상의 글은 입력할 수 없습니다.");
obj.value = s.substring(0,i - 2);
return false;
}
}
return true;
}
</script>
<textarea name="cnts" onKeyUp="getByteLength(this);"></textarea>