textarea byte check
script 2008. 9. 10. 14:44function textAreaLengthCheck(thisObj, maxLengthByte) {
var tempByteLength = 0, cutByteLength = 0;
for(var i = 0; i < thisObj.value.length; i++) {
if(escape(thisObj.value.charAt(i)).length > 4) {
tempByteLength += 2;
} else {
tempByteLength++;
}
if(tempByteLength < maxLengthByte) {
cutByteLength++;
}
}
if(tempByteLength > maxLengthByte) {
alert("max byte : " + maxLengthByte);
thisObj.value = thisObj.value.substring(0, (cutByteLength%2==1)?cutByteLength:cutByteLength+1);
}
}<textarea onkeyup="textAreaLengthCheck(this, 10)" name="test"></textarea>
ex.
'script' 카테고리의 다른 글
| xhtml dtd (0) | 2008.10.04 |
|---|---|
| offsetTop / offsetLeft (0) | 2008.10.01 |
| [Link] 고급 JavaScript 작성하기 (0) | 2008.09.25 |
| window.open() 팝업 (0) | 2008.09.23 |
| SyntaxHighlighter(Code google) Supported languages (0) | 2008.09.11 |
| javascript trim (4) | 2008.08.27 |
| jQuery API (2) | 2008.08.11 |
| window.onload 실행 순서(IE) (0) | 2008.07.30 |
| firstChild (0) | 2008.06.02 |
| javascript packer (0) | 2008.04.29 |