에디터에 셀렉트박스를 이용하여 지정된 문구 넣기

에디터에 셀렉트박스를 이용하여 지정된 문구 넣기

QA

에디터에 셀렉트박스를 이용하여 지정된 문구 넣기

본문

댓글은 textarea라서


<textarea id="wr_content" name="wr_content" maxlength="10000" rows="4" class="form-control" <?php if ($comment_min || $comment_max) { ?>onkeyup="check_byte('wr_content', 'char_count');" <?php } ?>><?php echo $c_wr_content;  ?></textarea>
<div class="col-sm-10 px-2">
  <select id="auto_comment" onchange="autoComment();">
   <option value="">자동멘트선택</option>
   <option data-value="1절">동해물과 백두산이 마르고 닳도록 하느님이 보우하사 국내 만세</option>
   <option data-value="2절">남산 위에 저 소나무 철갑을 두른 듯 바람서리 불변함은 우리 기상일세</option>
   <option data-value="3절">가을 하늘 공활한데 높고 구름 없이 밝은 달은 우리 가슴 일편단심일세애국가</option>
 </select>
</div>
 
<script>
 function autoComment() {
  var comment = $("#auto_comment option:selected").data('value');
  $("#wr_content").empty();
  $("#wr_content").append(comment);
 }
</script>

이렇게 셀렉트 박스로 원하는 문구를 한번에 나오게 했는데요..

 

qa게시판에서 답변을 달때 위처럼 이용하고 싶어서 view.answerform.skin 여기에 자동멘트코드를 추가해보려고 했습니다만

textarea가 아닌 에디터로 되어있는 거 같아서 어디부분에 자동멘트코드를 넣고 연결해야 하는지 감이 오질않습니다.ㅜㅜ

고수분들 에디터를 이용하여 셀렉트박스 자동멘트 코드를 사용하려면 어떻게 해야하는지요?

view.answerform.skin 코드 같이 올립니다.

고수분들의 답변을 기다립니다.

 


<?php
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
?>
 
<section id="bo_v_ans_form" class="mb-3 py-3 pb-4 border-top border-bottom">
 
    <?php 
    // 관리자이면 답변등록 
    if($is_admin) { 
        // 첨부파일
        na_script('fileinput');
    ?>
    <form name="fanswer" method="post" action="./qawrite_update.php" onsubmit="return fwrite_submit(this);" enctype="multipart/form-data" autocomplete="off" class="px-3 px-sm-0">
    <input type="hidden" name="qa_id" value="<?php echo $view['qa_id']; ?>">
    <input type="hidden" name="w" value="a">
    <input type="hidden" name="sca" value="<?php echo $sca ?>">
    <input type="hidden" name="stx" value="<?php echo $stx; ?>">
    <input type="hidden" name="page" value="<?php echo $page; ?>">
    <input type="hidden" name="token" value="<?php echo get_text($token); ?>">
        <div class="row mx-n2">
            <div class="col-sm-9 px-2">
                <div class="input-group mb-3">
                    <div class="input-group-prepend">
                        <span class="input-group-text" id="basic-addon1">답변 제목</span>
                    </div>  
                    <input type="text" name="qa_subject" value="답변 드립니다." id="qa_subject" required class="form-control required" maxlength="255">
                </div>
            </div>
 
            <?php if ($is_dhtml_editor) { ?>
                <input type="hidden" name="qa_html" value="1">
            <?php } else { ?>
                <div class="col-sm-3 px-2">
                    <div class="custom-control custom-checkbox mb-2 mt-0 mt-sm-1 ">
                        <input type="checkbox" name="qa_html" value="<?php echo $html_value ?>" id="qa_html" onclick="html_auto_br(this);" class="custom-control-input" <?php echo $html_checked ?>>
                        <label class="custom-control-label" for="qa_html"><span>HTML</span></label>
                    </div>
                </div>
            <?php } ?>
        </div>
        
        <div class="form-group mb-3">
            <?php echo $editor_html; // 에디터 사용시는 에디터로, 아니면 textarea 로 노출 ?>
 
            <?php if ($is_dhtml_editor) { ?>
                <style> #qa_content { border:0; display:none; } </style>
            <?php } else { ?>
                <script> $("#qa_content").hide().addClass("form-control").show(); </script>
            <?php } ?>
        </div>
 
        <div class="form-group f-sm mb-4">
            <div class="input-group mb-2">
                <div class="input-group-prepend">
                    <label class="input-group-text" for="bf_file1">파일 1</label>
                </div>
                <div class="custom-file">
                    <input type="file" name="bf_file[1]" class="custom-file-input" title="파일 용량 <?php echo $upload_max_filesize; ?> 이하만 업로드 가능" id="bf_file1">
                    <label class="custom-file-label" for="bf_file1" data-browse="선택"></label>
                </div>
            </div>
 
            <div class="input-group">
                <div class="input-group-prepend">
                    <label class="input-group-text" for="bf_file2">파일 2</label>
                </div>
                <div class="custom-file">
                    <input type="file" name="bf_file[2]" class="custom-file-input" title="파일 용량 <?php echo $upload_max_filesize; ?> 이하만 업로드 가능" id="bf_file2">
                    <label class="custom-file-label" for="bf_file2" data-browse="선택"></label>
                </div>
            </div>
        </div>
 
        <div class="text-center">
            <button type="submit" id="btn_submit" accesskey="s" class="btn btn-primary">답변등록</button>
        </div>
    </form>
 
    <script>
    function html_auto_br(obj) {
        if (obj.checked) {
            result = confirm("자동 줄바꿈을 하시겠습니까?\n\n자동 줄바꿈은 게시물 내용중 줄바뀐 곳을<br>태그로 변환하는 기능입니다.");
            if (result)
                obj.value = "2";
            else
                obj.value = "1";
        }
        else
            obj.value = "";
    }
 
    function fwrite_submit(f) {
 
        <?php echo $editor_js; // 에디터 사용시 자바스크립트에서 내용을 폼필드로 넣어주며 내용이 입력되었는지 검사함   ?>
 
        var subject = "";
        var content = "";
        $.ajax({
            url: g5_bbs_url+"/ajax.filter.php",
            type: "POST",
            data: {
                "subject": f.qa_subject.value,
                "content": f.qa_content.value
            },
            dataType: "json",
            async: false,
            cache: false,
            success: function(data, textStatus) {
                subject = data.subject;
                content = data.content;
            }
        });
 
        if (subject) {
            alert("제목에 금지단어('"+subject+"')가 포함되어있습니다");
            f.qa_subject.focus();
            return false;
        }
 
        if (content) {
            alert("내용에 금지단어('"+content+"')가 포함되어있습니다");
            if (typeof(ed_qa_content) != "undefined")
                ed_qa_content.returnFalse();
            else
                f.qa_content.focus();
            return false;
        }
 
        $.ajax({
            type: "POST",
            url: g5_bbs_url+"/ajax.write.token.php",
            data: { 'token_case' : 'qa_write' },
            cache: false,
            async: false,
            dataType: "json",
            success: function(data) {
                if (typeof data.token !== "undefined") {
                    token = data.token;
                    if(typeof f.token === "undefined")
                        $(f).prepend('<input type="hidden" name="token" value="">');
                    $(f).find("input[name=token]").val(token);
                }
            }
        });
 
        document.getElementById("btn_submit").disabled = "disabled";
 
        return true;
    }
    </script>
    <?php } else { ?>
        <div id="ans_msg" class="px-3 pt-2 text-center">문의에 대한 답변을 준비 중입니다.</div>
    <?php } ?>
</section>
 
<div class="px-3 px-sm-0 pb-3">
    <div class="na-table d-table w-100">
        <div class="d-table-row">
            <div class="d-table-cell nw-3 text-left">
                <?php if ($prev_href) { ?>
                    <a href="<?php echo $prev_href ?>" class="btn btn_b01 nofocus" title="이전 문의">
                        <i class="fa fa-chevron-left fa-md" aria-hidden="true"></i>
                        <span class="sr-only">이전 문의</span>
                    </a>
                <?php } ?>
            </div>
            <div class="d-table-cell text-center">
                <a href="<?php echo $list_href ?>" class="btn btn_b01 nofocus" role="button"  title="목록">
                    <i class="fa fa-list fa-md" aria-hidden="true"></i>
                    <span class="sr-only">목록</span>
                </a>  
            </div>
            <div class="d-table-cell nw-3 text-right">
                <?php if ($next_href) { ?>
                    <a href="<?php echo $next_href ?>" class="btn btn_b01 nofocus" title="다음 문의">
                        <i class="fa fa-chevron-right fa-md" aria-hidden="true"></i>
                        <span class="sr-only">다음 문의</span>
                    </a>
                <?php } ?>
            </div>
        </div>
    </div>
</div>
 

이 질문에 댓글 쓰기 :

답변 1

※ https://m.blog.naver.com/monkeychoi/60171723220
<script>
 function autoComment() {
  var comment = $("#auto_comment option:selected").data('value');
  oEditors.getById["wr_content"].exec("PASTE_HTML", comment);
 }
</script>

답변을 작성하시기 전에 로그인 해주세요.
전체 407
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT