textarea byte check
script 2008. 9. 10. 14:4401.
function
textAreaLengthCheck(thisObj, maxLengthByte) {
02.
var
tempByteLength = 0, cutByteLength = 0;
03.
for
(
var
i = 0; i < thisObj.value.length; i++) {
04.
if
(escape(thisObj.value.charAt(i)).length > 4) {
05.
tempByteLength += 2;
06.
}
else
{
07.
tempByteLength++;
08.
}
09.
10.
11.
12.
if
(tempByteLength < maxLengthByte) {
13.
cutByteLength++;
14.
}
15.
}
16.
if
(tempByteLength > maxLengthByte) {
17.
alert(
"max byte : "
+ maxLengthByte);
18.
thisObj.value = thisObj.value.substring(0, (cutByteLength%2==1)?cutByteLength:cutByteLength+1);
19.
}
20.
21.
}
<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 |