방금전 질문했었는데요..

방금전 질문했었는데요..

QA

방금전 질문했었는데요..

본문


        <tr>
            <th scope="row">상품위치</th>
            <td>
                <?php echo help("메인화면에 유형별로 출력할때 사용합니다.\n이곳에 체크하게되면 상품리스트에서 유형별로 정렬할때 체크된 상품이 가장 먼저 출력됩니다."); ?>
                <input type="checkbox" name="it_flag_kr" value="1" data-name='대한민국 ' <?php echo ($it['it_flag_kr'] ? "checked" : ""); ?> id="it_flag_kr">
                <label for="it_flag_kr"><img src="<?php echo G5_SHOP_URL; ?>/img/icon_kr.png" alt=""> KR</label>
                <input type="checkbox" name="it_flag_lk" value="1" data-name='스리랑카 ' <?php echo ($it['it_flag_lk'] ? "checked" : ""); ?> id="it_flag_lk">
                <label for="it_flag_lk"><img src="<?php echo G5_SHOP_URL; ?>/img/icon_lk.png" alt=""> LK</label>
                <input type="checkbox" name="it_flag_id" value="1" data-name='인도네시아 ' <?php echo ($it['it_flag_id'] ? "checked" : ""); ?> id="it_flag_id">
                <label for="it_flag_id"><img src="<?php echo G5_SHOP_URL; ?>/img/icon_id.png" alt=""> ID</label>
                <input type="checkbox" name="it_flag_bd" value="1" data-name='방글라데시 ' <?php echo ($it['it_flag_bd'] ? "checked" : ""); ?> id="it_flag_bd">
                <label for="it_flag_bd"><img src="<?php echo G5_SHOP_URL; ?>/img/icon_bd.png" alt=""> BD</label>
                <!-- <button id="alls">전체선택</button>
                <button id="allr">전체해제</button> -->
            </td>
            <td class="td_grpset">
                <input type="checkbox" name="chk_ca_it_type" value="1" id="chk_ca_it_type">
                <label for="chk_ca_it_type">분류적용</label>
                <input type="checkbox" name="chk_all_it_type" value="1" id="chk_all_it_type">
                <label for="chk_all_it_type">전체적용</label>
            </td>
        </tr>
        
        <tr>
            <th scope="row">상품유형</th>
            <td>
                <?php echo help("메인화면에 유형별로 출력할때 사용합니다.\n이곳에 체크하게되면 상품리스트에서 유형별로 정렬할때 체크된 상품이 가장 먼저 출력됩니다."); ?>
                <input type="checkbox" name="it_type1" value="1" <?php echo ($it['it_type1'] ? "checked" : ""); ?> id="it_type1">
                <label for="it_type1">히트 <img src="<?php echo G5_SHOP_URL; ?>/img/icon_hit.gif" alt=""></label>
                <input type="checkbox" name="it_type2" value="1" <?php echo ($it['it_type2'] ? "checked" : ""); ?> id="it_type2">
                <label for="it_type2">추천 <img src="<?php echo G5_SHOP_URL; ?>/img/icon_rec.gif" alt=""></label>
                <input type="checkbox" name="it_type3" value="1" <?php echo ($it['it_type3'] ? "checked" : ""); ?> id="it_type3">
                <label for="it_type3">신상품 <img src="<?php echo G5_SHOP_URL; ?>/img/icon_new.gif" alt=""></label>
                <input type="checkbox" name="it_type4" value="1" <?php echo ($it['it_type4'] ? "checked" : ""); ?> id="it_type4">
                <label for="it_type4">인기 <img src="<?php echo G5_SHOP_URL; ?>/img/icon_best.gif" alt=""></label>
                <input type="checkbox" name="it_type5" value="1" <?php echo ($it['it_type5'] ? "checked" : ""); ?> id="it_type5">
                <label for="it_type5">할인 <img src="<?php echo G5_SHOP_URL; ?>/img/icon_discount.gif" alt=""></label>
            </td>
            <td class="td_grpset">
                <input type="checkbox" name="chk_ca_it_type" value="1" id="chk_ca_it_type">
                <label for="chk_ca_it_type">분류적용</label>
                <input type="checkbox" name="chk_all_it_type" value="1" id="chk_all_it_type">
                <label for="chk_all_it_type">전체적용</label>
            </td>
        </tr>
        
        </tr>
        <tr>
            <th scope="row"><label for="it_maker">상품위치</label></th>
            <td>
                <?php echo help("입력하지 않으면 상품상세페이지에 출력하지 않습니다."); ?>
                <input type="text" name="it_location" value="<?php echo get_text($it['it_location']); ?>" id="it_location" class="frm_input" size="40">
            </td>
            <td class="td_grpset">
                <input type="checkbox" name="chk_ca_it_maker" value="1" id="chk_ca_it_maker">
                <label for="chk_ca_it_maker">분류적용</label>
                <input type="checkbox" name="chk_all_it_maker" value="1" id="chk_all_it_maker">
                <label for="chk_all_it_maker">전체적용</label>
            </td>
        </tr>
            <script>
              $(function() {
        $("input[type='checkbox']").on('click', function() {
          //checkbox 형태의 input태그 가 클릭될 때 다음 함수를 실행한다.
          var write = '';
          //write 변수 선언
          $("input[type='checkbox']:checked").each(function() {
            //checked 된 input 태그들 각각 write 변수에 내용을 합친다.
            write += $(this).data("name");
          });
          $('#it_location').val(write);
          //textarea 에 write 에 담긴 내용 셋팅
        });
        $('#alls').on('click', function() {
          var alltext = '';
          $("input[type='checkbox']").prop('checked', true).each(function(index) {
            alltext += $(this).data("name")
          });
          $('#it_location').val(alltext)
        });
        $('#allr').on('click', function() {
          $('input').prop('checked', false)
          $('#it_location').val('');
        });
      });
        </script>

 

3696779805_1564912847.7291.png

[그림1]

 

3696779805_1564912869.9943.png

[그림2]

 

방금전 올렸던 질문

https://sir.kr/qa/317614#answer_317618

 

블랙캣님의 도움으로 막힌 문제를 해결하니 또다른 문제가 생기네요.

 

설명을 드리자면 그림1은 상품유형의 히트와 추천이 체크박스가 클릭된 상태에서 undefinedundefined 두개가 입력이된 상태입니다.

그림2는 대한민국과 스리랑카가 체크박스 선택이 되어서 대한민국 스리랑카 undefinedundefined로 입력이된 상태입니다.

 

스코프 선택은 상품위치의 it_location입니다.

jQuery의 지역변수 전역변수 문제인듯한데..

상품유형 선택된 상태에서도 undefined가 안나오게 하려면 어떻게 하면 되는것인지 고수님들의 도움을 바랍니다.

이 질문에 댓글 쓰기 :

답변 1

흠.....
 $("input[type='checkbox']").on('click'function() {  이면 뭔가를 클릭했던 순간에 변수를 수집하고 생성할텐데.... 
페이지를 열었을때는 변수가 생성 상태가 아니니까....

아무것도 클릭안하고 저장한다면 당현히 문제가 나겠네요? 
테스트는 안해봤지만.....이런식으로 돌런지모르겠네요 




         <script>
             var write = '';
             var allText='';
              $(function() {
        $("input[type='checkbox']").on('click', function() {
          //checkbox 형태의 input태그 가 클릭될 때 다음 함수를 실행한다.
          
          //write 변수 선언
          $("input[type='checkbox']:checked").each(function() {
            //checked 된 input 태그들 각각 write 변수에 내용을 합친다.
            write += $(this).data("name");
          });
          $('#it_location').val(write);
          //textarea 에 write 에 담긴 내용 셋팅
        });
        $('#alls').on('click', function() {
            $("input[type='checkbox']").prop('checked', true).each(function(index) {
            alltext += $(this).data("name")
          });
          $('#it_location').val(alltext)
        });
        $('#allr').on('click', function() {
          $('input').prop('checked', false)
          $('#it_location').val('');
        });
      });
        </script>
답변을 작성하시기 전에 로그인 해주세요.
전체 1,012
QA 내용 검색

회원로그인

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