본문 바로가기

BMS/javaScript

textarea 글자 라인 수만큼 rows를 늘려준다.

<td class="tbl_data" bgcolor="#FFFFFF" height="18" colspan="3" style="padding-top :5px ;padding-bottom :5px ;" align="center">
                    <textarea name="approvalInfomation" class="input" style="width:98%;" onkeyup="fncSyncTextarea();"><%=investmentInfoForm.getApporval_info()%></textarea>
                  </td>


=====================================================================================================


<%-- ======================================================================
   Function    :  fncSyncTextarea
   Param       :  c 1자짜리 문자
   Return      :  갯수
   description :  문자열에 특정 Char갯수를 알아온다.
 ======================================================================== --%>
 function fncSyncTextarea() {
     var obj = form.approvalInfomation;
     var rows = obj.value.countChar('\n') + 1;
     obj.rows = (rows<=7)? 7:rows;
 } // end of fncSyncTextarea() //


=====================================================================================================

/**
 * @type   : prototype_function
 * @access : public
 * @desc   : 문자열에 특정 Char갯수를 알아온다.
 * <pre>
 *     var str = "a.b.c.d.e"
 *     var cnt = str.countChar(".");
 * </pre>
 * 위의 예에서 cnt는 4 가 된다.
 * @param  : c 1자짜리 문자
 * @return : 갯수
 * @author :
 */
String.prototype.countChar = function(c) {
 var cnt = 0;
 var buf = this;
 while(buf!=null && buf!=c && buf.indexOf(c)>=0) {
     buf = buf.substring(buf.indexOf(c)+1);
     cnt++;
 }
 return cnt;
}