본문 바로가기

Programming/JavaScript

자바스크립트에서 배열처리 및 숫자만입력하기

 // 숫자만 입력받는 함수
 function checkForNumber()
 {
    var key = event.keyCode;

    if (!(key == 8 || key == 9 || key == 13 || key == 46 || key == 144 || (key >= 48 && key <= 57) || key == 110 || key == 190))
    {
        event.returnValue = false;
    }
 }

 function dlyUpdate()
 {
  var mpyPrmGoal = new Array();
  var covrPrmGoal = new Array();
  var fncePrmGoal = new Array();
  var slctDof = new Array();

  for (i = 0; i < document.form1.elements["MPY_PRM_GOAL[]"].length; i++)
  {
   mpyPrmGoal[i] = document.form1.elements["MPY_PRM_GOAL[]"][i].value;
   covrPrmGoal[i] = document.form1.elements["COVR_PRM_GOAL[]"][i].value;
   fncePrmGoal[i] = document.form1.elements["FNCE_PRM_GOAL[]"][i].value;
   slctDof[i] = document.form1.elements["SLCT_DOF[]"][i].value;
  }
 }

-- jsp단 예제
                    <tr height=25>
                      <td class=sc align=center><%=ORG_NM%></td>
                      <td bgcolor=#666666></td>
                      <td class=sc align=right><input name="MPY_PRM_GOAL[]" type="text" value="<%=MPY_PRM_GOAL%>" onKeyPress="checkForNumber();" style="ime-mode:disabled;"  size="18" maxlength="17"></td>
                      <td bgcolor=#666666></td>
                      <td class=sc align=right><input name="COVR_PRM_GOAL[]" type="text" value="<%=COVR_PRM_GOAL%>" onKeyPress="checkForNumber();" style="ime-mode:disabled;"  size="18" maxlength="17"></td>
                      <td bgcolor=#666666></td>
                      <td class=sc align=right><input name="FNCE_PRM_GOAL[]" type="text" value="<%=FNCE_PRM_GOAL%>" onKeyPress="checkForNumber();" style="ime-mode:disabled;"  size="18" maxlength="17"></td>
                      <input type="hidden" name="SLCT_DOF[]" value="<%=SLCT_DOF%>">
                    </tr>
자바스크립트에서 숫자만 입력할때 한글일경우는 오류가 나므로 style="ime-mode:disabled;" 요옵션을 인풋박스에 주면 된다...