본문 바로가기

HTML/JS/CSS

textarea 제어. 몇가지.

출처 : http://cafe.naver.com/bigcase.cafe?iframe_url=/ArticleRead.nhn%3Farticleid=188


<SCRIPT LANGUAGE="JavaScript">
        function storeCaret (textel){
                if (textel.createTextRange){
                  textel.caretPos = document.selection.createRange().duplicate();
                }
        }
        function insertatcaret (textel, text){
          //text = "<b>" + text + "</b>";
          text = text;        
                if (textel.createTextRange && textel.caretPos){
                  var caretPos = textel.caretPos;
                  caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
                }else{
                  textel.value  = textel.value  + text;
                }
        }
  </SCRIPT>

<form>
<textarea name="admin_contents_sms_value" ROWS="10" COLS="50" WRAP="soft" ONSELECT="storeCaret(this);" ONCLICK="storeCaret(this);" ONKEYUP="storeCaret(this);">원하는 위치에 원하는 문자 삽입</textarea>
<br>
<input type=text name=tem_Code value='입력하세요'>
<input type="button" value="삽입" onClick="insertatcaret(this.form.admin_contents_sms_value,this.form.tem_Code.value);">
</form>

'HTML/JS/CSS' 카테고리의 다른 글

javascript comma 찍어주기. 풀어주기.  (3) 2008.12.01
[Javascript] parentNode, ParentElement  (0) 2008.11.14
HTML/Javasciprt 표준 (중요해용)  (0) 2008.09.22