http://oxtag.com/html/ex/ex/ex7.html

  1. <SCRIPT LANGUAGE="JavaScript">
  2. <!--
  3. function move_focus() {
  4. len = form1.pos1.value.length
  5. aa = String.fromCharCode(event.keyCode)
  6. if(len == 2) {
  7.         form1.pos1.value = form1.pos1.value + aa ;
  8.         form1.pos2.focus() ;
  9. }
  10. }
  11. function enter_move() {
  12. if(event.keyCode == 13) {
  13.     form1.nn2.focus()
  14. }
  15. }
  16. //-->
  17. </SCRIPT>
  18. </HEAD>
  19. <BODY>
  20. <form name=form1>
  21.     ○ 3글자를 넣으면 포커스가 이동합니다. <br>
  22.     우편번호 : <input type=text name=pos1 onKeypress='move_focus("form1.pos1")'> - <input type=text name=pos2 onfocus="this.value=''" ><p>
  23.         ○ 엔터를 치면 포커스가 이동합니다.<br>
  24.         name    : <input type=text name=nn onKeypress='enter_move()'><br>
  25.         별명     : <input type=text name=nn2>
  26. </form>
  27. <br>
  28. ○ 텍스트 박스 내의 글자 길이 제한 체크 <p>
  29. <SCRIPT LANGUAGE="JavaScript">
  30. <!--
  31. function MsgLenCheck(f) {
  32.     MsgLen = getStrLen(f.value)
  33.          ShowMsgLen.innerHTML = MsgLen + '/20';
  34.         
  35.         if (MsgLen > 20 )
  36.         {
  37.                 alert(" 20 byte 이상은 저장되지 않습니다. ")
  38.         }
  39. }
  40. function getStrLen(str)
  41. {
  42.         var len=0, j;
  43.         
  44.         for (i=0, j=str.length;        i < j ; i++, len++)
  45.         {
  46.                 if ( (str.charCodeAt(i)<0)||(str.charCodeAt(i)>127) )
  47.                 {
  48.                         len = len+1;
  49.                 }
  50.         }
  51.         return len;
  52. }
  53. //-->
  54. </SCRIPT>
  55. <div id='ShowMsgLen' name='ShowMsgLen'> 0 / 20 </div> <p>
  56. <textarea name=content rows=10 cols=80 onkeyup="MsgLenCheck(this)" style="font-size:9pt;"></textarea>
Posted by 알 수 없는 사용자
,