웹마스터 팁
page_full_width" class="col-xs-12" |cond="$__Context->page_full_width">
textarea 입력받는 글자수 제한하는 스크립트
2002.01.17 19:53
<!-- TWO STEPS TO INSTALL LIMIT TEXTAREA:
<!-- textarea의 입력 제한 설치 2단계 -->
1. Copy the coding into the HEAD of your HTML document
<!-- //1. html의 head에 소스를 넣어준다. -->
2. Add the last code into the BODY of your HTML document -->
<!-- //2. html의 body에 소스를 넣어준다. -->
<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->
<!-- //1단계 : html의 head에 아래의 소스를 넣어라. -->
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Ronnie T. Moore -->
<!-- Web Site: The JavaScript Source -->
<!-- //원작자와 사이트명 -->
<!-- Dynamic 'fix' by: Nannette Thacker -->
<!-- Web Site: http://www.shiningstar.net -->
<!-- //수정한사람과 사이트명 -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- //이곳에 더많은 좋은 정보가 있다. -->
<!-- Begin
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
countfield.value = maxlimit - field.value.length;
}
End -->
<!-- // textcounter 함수의 시작과 끝, 위의 부분을 head에 넣어줌 -->
</script>
</HEAD>
<!-- STEP TWO: Copy this code into the BODY of your HTML document -->
<!-- //2단계 : html의 body에 아래의 코드를 넣어라. -->
<BODY>
<!-- textCounter() parameters are: text field, the count field, max length -->
<!-- //textcounter()에 사용되는 것들 : 텍스트필드, 카운트필드, 최대입력수 -->
<!-- //여기서부터는 위의 스크립트를 사용한 예제임(125자로 제한). 알맞게 수정하면 됨.... -->
<center>
<form name=myform action="YOUR-SCRIPT.CGI">
<font size="1" face="arial, helvetica, sans-serif"> ( You may enter up to 125 characters. )<br>
<textarea name=message wrap=physical cols=28 rows=4 onKeyDown="textCounter(this.form.message,this.form.remLen,125);" onKeyUp="textCounter(this.form.message,this.form.remLen,125);"></textarea>
<br>
<input readonly type=text name=remLen size=3 maxlength=3 value="125"> characters left</font>
<!-- 몇자남았는지카운트해주는부분 -->
</form>
</center>
<p><center>
<font face="arial, helvetica" SIZE="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>
<!-- Script Size: 1.37 KB -->
쉽게 말해서 head에 이걸 넣어줍니다.
<SCRIPT LANGUAGE="JavaScript">
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
countfield.value = maxlimit - field.value.length;
}
</script>
body에는 위의 예처럼 사용합니다. (맞게 수정하시면 됩니다.)
<form name=myform action="YOUR-SCRIPT.CGI">
<font size="1" face="arial, helvetica, sans-serif"> ( You may enter up to 125 characters. )<br>
<textarea name=message wrap=physical cols=28 rows=4 onKeyDown="textCounter(this.form.message,this.form.remLen,125);" onKeyUp="textCounter(this.form.message,this.form.remLen,125);"></textarea>
<br>
<input readonly type=text name=remLen size=3 maxlength=3 value="125"> characters left</font>
</form>
<!-- textarea의 입력 제한 설치 2단계 -->
1. Copy the coding into the HEAD of your HTML document
<!-- //1. html의 head에 소스를 넣어준다. -->
2. Add the last code into the BODY of your HTML document -->
<!-- //2. html의 body에 소스를 넣어준다. -->
<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->
<!-- //1단계 : html의 head에 아래의 소스를 넣어라. -->
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Ronnie T. Moore -->
<!-- Web Site: The JavaScript Source -->
<!-- //원작자와 사이트명 -->
<!-- Dynamic 'fix' by: Nannette Thacker -->
<!-- Web Site: http://www.shiningstar.net -->
<!-- //수정한사람과 사이트명 -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- //이곳에 더많은 좋은 정보가 있다. -->
<!-- Begin
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
countfield.value = maxlimit - field.value.length;
}
End -->
<!-- // textcounter 함수의 시작과 끝, 위의 부분을 head에 넣어줌 -->
</script>
</HEAD>
<!-- STEP TWO: Copy this code into the BODY of your HTML document -->
<!-- //2단계 : html의 body에 아래의 코드를 넣어라. -->
<BODY>
<!-- textCounter() parameters are: text field, the count field, max length -->
<!-- //textcounter()에 사용되는 것들 : 텍스트필드, 카운트필드, 최대입력수 -->
<!-- //여기서부터는 위의 스크립트를 사용한 예제임(125자로 제한). 알맞게 수정하면 됨.... -->
<center>
<form name=myform action="YOUR-SCRIPT.CGI">
<font size="1" face="arial, helvetica, sans-serif"> ( You may enter up to 125 characters. )<br>
<textarea name=message wrap=physical cols=28 rows=4 onKeyDown="textCounter(this.form.message,this.form.remLen,125);" onKeyUp="textCounter(this.form.message,this.form.remLen,125);"></textarea>
<br>
<input readonly type=text name=remLen size=3 maxlength=3 value="125"> characters left</font>
<!-- 몇자남았는지카운트해주는부분 -->
</form>
</center>
<p><center>
<font face="arial, helvetica" SIZE="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>
<!-- Script Size: 1.37 KB -->
쉽게 말해서 head에 이걸 넣어줍니다.
<SCRIPT LANGUAGE="JavaScript">
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
countfield.value = maxlimit - field.value.length;
}
</script>
body에는 위의 예처럼 사용합니다. (맞게 수정하시면 됩니다.)
<form name=myform action="YOUR-SCRIPT.CGI">
<font size="1" face="arial, helvetica, sans-serif"> ( You may enter up to 125 characters. )<br>
<textarea name=message wrap=physical cols=28 rows=4 onKeyDown="textCounter(this.form.message,this.form.remLen,125);" onKeyUp="textCounter(this.form.message,this.form.remLen,125);"></textarea>
<br>
<input readonly type=text name=remLen size=3 maxlength=3 value="125"> characters left</font>
</form>
댓글 5
-
박신용
2002.01.20 04:23
ㅡ,.ㅡ 영어무지 잘하시네여..초보를 위해 올리셨다면 설명은 좀 한글로 쓰시던가 초보들 보기엔 다 프로그램인지 알것네....헉시 한글 몰르심 멀라두.. -
오기
2002.01.20 13:41
http://javascript.internet.com/forms/limit-textarea.html
이 소스를 가져온 페이지 입니다.
<!-- -->는 주석이고 이 부분을 제외하면 실제 소스는 얼마 되지 않습니다.
나머지 소스도 태그만 아시면 이해가 어렵지 않구요...
영어 못하지만 여기에 달린 영어로된 주석이 어렵다고는 생각 안합니다. ㅡ.ㅡ -
WOWpc
2002.01.28 04:04
한글도 1 문자로 인식하는데 문제가 있군요.
한글은 2 byte 로 처리해야 하는데 말이죠..
외국애들이 만든거라 어쩔 수 없나봅니다. -
김의주
2002.01.30 11:01
오... 이런건 그냥 문자(SMS)보내는 거에서 따서오면 되요 --; -
김동빈
2003.01.12 23:32
한글은 제한 안됩니다...