자바스크립트 질문입니다.

자바스크립트 질문입니다.

QA

자바스크립트 질문입니다.

본문

위시리스트 이구요.

fwishlist_check 이 함수 보시면

act == "alldelete" 일때


var allInp = document.getElementsByTagName("input");
                for (var i=0, max=allInp.length; i <max; i++)
                {
                    if(allInp[i].type === 'checkbox'){
                        allInp[i].checked = true;
                    }
                }

이게 실행 되는데요..

제가 원하는건

"전체삭제 (alldelete)" 버튼을 눌렀을때

모든 체크박스를 checked 로 만들고 싶거든요;;

근데 이게 밑에 confirm 창에서 확인을 눌러야만..

checked 가 됩니다;

 

confirm 창 뜨기전에 코드를 넣어도 

마찬가지네유;;

 

원하는 로직은

전체삭제 <- act == 'alldelete' 버튼을 누르면

모든 체크박스들이 체크된 뒤 confirm 창이 노출!

후에 확인을 누르면 wishaction 파일이 실행되고 

취소 누르면 checked = false 로 만드는건데..

다 잘 작동하는데

전체삭제 눌렀을 때 체크값으로 변하는것만 말썽이네요;

 

 

여기는 wishlist.php 입니다.


<?php
include_once('./_common.php');
// 테마에 wishlist.php 있으면 include
if(defined('G5_THEME_SHOP_PATH')) {
    $theme_wishlist_file = G5_THEME_MSHOP_PATH.'/wishlist.php';
    if(is_file($theme_wishlist_file)) {
        include_once($theme_wishlist_file);
        return;
        unset($theme_wishlist_file);
    }
}
$g5['title'] = "관심 상품";
include_once(G5_MSHOP_PATH.'/_head.php');
?>
<section id="smb_my_ov">
    <h2>마이페이지 개요</h2>
    <table>
        <caption class="sound_only">마이페이지 하부 메뉴</caption>
        <thead>
            <tr>
                <th>상품 관리</th>
                <th>구매 관리</th>
                <th>활동 관리</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td><a href="<?php echo G5_SHOP_URL ?>/wishlist.php" title="관심 상품">관심 상품</a></td>
                <td><a href="<?php echo G5_SHOP_URL ?>/orderinquiry.php" title="주문내역">주문내역</a></td>
                <td><a href="<?php echo G5_SHOP_URL ?>/mypage_itemqalist.php" title="1:1문의">1:1문의</a></td>
            </tr>
            <tr>
                <td><a href="<?php echo G5_SHOP_URL ?>/today_view.php" title="오늘 본 상품">오늘 본 상품</a></td>
                <td><a href="<?php echo G5_SHOP_URL ?>/cart.php" title="장바구니">장바구니</a></td>
                <td><a href="<?php echo G5_SHOP_URL ?>/mypage_itemuselist.php" title="구매후기">구매후기</a></td>
            </tr>
            <tr>
                <td></td>
                <td></td>
                <td><a href="<?php echo G5_BBS_URL ?>/board.php?bo_table=ShopAlliance&sca=&sop=and&sfl=mb_id%2C1&stx=<?php echo $member['mb_id'] ?>" title="제휴제안">제휴제안</a></td>
            </tr>
        </tbody>
    </table>
</section>
<div id="sod_ws">
    <form name="fwishlist" method="post" action="./wishaction.php">
    <input type="hidden" name="act"       value="multi">
    <input type="hidden" name="sw_direct" value="">
    <input type="hidden" name="prog"      value="wish">
    <?php 
        $sql = " select a.wi_id, a.wi_time, b.*
                   from {$g5['g5_shop_wish_table']} a left join {$g5['g5_shop_item_table']} b on ( a.it_id = b.it_id )
                  where a.mb_id = '{$member['mb_id']}'
                  order by a.wi_id desc ";
        $result = sql_query($sql);
        $wish_count = sql_num_rows($result);
        
        if ($wish_count) {
    ?>
        <div id="wish_chk">
            <input type="checkbox" name="ct_all" value="1" id="ct_all">
            <label for="ct_all">전체상품 선택</label>
        </div>
        <ul id="wish_li">
    <?php
        } // if ($wish_count)
        for ($i=0; $row = sql_fetch_array($result); $i++) {
            $out_cd = '';
            $sql = " select count(*) as cnt from {$g5['g5_shop_item_option_table']} where it_id = '{$row['it_id']}' and io_type = '0' ";
            $tmp = sql_fetch($sql);
            if($tmp['cnt'])
                $out_cd = 'no';
            $it_price = get_price($row);
            if ($row['it_tel_inq']) $out_cd = 'tel_inq';
            $image = get_it_image($row['it_id'], 70, 70);
    ?>
        <li>
            <div class="wish_info">
                <a href="<?php echo G5_SHOP_URL; ?>/item.php?it_id=<?php echo $row['it_id']; ?>" class="<?php if(is_soldout($row['it_id'])) { echo 'soldout';}?>">
                    <?php if(is_soldout($row['it_id'])) { // 품절검사 ?>
                        <span>품절</span>
                    <?php } ?>
                    <?php echo stripslashes($row['it_name']); ?>
                </a>
                <span class="info_date"><?php echo substr($row['wi_time'],2,-3); ?></span>
            </div>
            <div class="wish_chk">
                <input type="hidden" name="out_cd_chk" value="<?php echo $out_cd; ?>">
                <input type="checkbox" name="chk_it_id[<?php echo $i; ?>]" value="1" id="chk_it_id_<?php echo $i; ?>">
                <label for="chk_it_id_<?php echo $i; ?>" class="list_chk">체크박스</label>
                <input type="hidden" name="it_id[<?php echo $i; ?>]" value="<?php echo $row['it_id']; ?>">
                <input type="hidden" name="io_type[<?php echo $row['it_id']; ?>][0]" value="0">
                <input type="hidden" name="io_id[<?php echo $row['it_id']; ?>][0]" value="">
                <input type="hidden" name="io_value[<?php echo $row['it_id']; ?>][0]" value="<?php echo $row['it_name']; ?>">
                <input type="hidden" name="ct_qty[<?php echo $row['it_id']; ?>][0]" value="1">
            </div>
        </li>
        <?php
        }
        if ($i == 0)
            echo '<li class="empty_table">관심 상품이 없습니다.</li>';
        ?>
    </ul>

    <div id="sod_ws_act">
        <?php if ($i != 0) { ?>
            <input type="hidden" name="url" value="./orderform.php">
            <input type="hidden" name="records" value="<?php echo $i; ?>">
            <div>
                <button type="button" class="btn_del" onclick="return fwishlist_check(document.fwishlist,'seldelete');" class="btn01" style="margin-right:2%">선택삭제</button><button type="button" class="btn_del" onclick="return fwishlist_check(document.fwishlist,'alldelete');" class="btn01">전체삭제</button>
            </div>
        <?php } ?>
    </div>
    </form>
</div>
<script>
    // 모두선택
    $("input[name=ct_all]").click(function() {
        if($(this).is(":checked"))
            $("input[name^=chk_it_id]").attr("checked", true);
        else
            $("input[name^=chk_it_id]").attr("checked", false);
    });
    // 체크값에 따른 전체선택 변경
    $("input[name^=chk_it_id]").click(function(){
        if ($("input[name^=chk_it_id]").length == $("input[name^=chk_it_id]:checked").length)
        {
            $("input[name=ct_all]").attr("checked", true);
        } else {
            $("input[name=ct_all]").attr("checked", false);
        }
    });
    function fwishlist_check(f, act)
    {
        var k = 0;
        var length = f.elements.length;
        for(i=0; i<length; i++) {
            if (f.elements[i].checked) {
                k++;
            }
        }
        if (act == "alldelete")
        {
            if(confirm("정말 삭제하시겠습니까?")) {
                f.act.value = act;
                f.submit();
                var allInp = document.getElementsByTagName("input");
                for (var i=0, max=allInp.length; i <max; i++)
                {
                    if(allInp[i].type === 'checkbox'){
                        allInp[i].checked = true;
                    }
                }
            } else {
                return;
            }
        }
        else
        {
            if($("input[name^=chk_it_id]:checked").size() < 1) {
                alert("삭제하실 상품을 하나이상 선택해 주십시오.");
                return false;
            }
            if(confirm("정말 삭제하시겠습니까?")) {
                f.act.value = act;
                f.submit();
            } else {
                return;
            }
        }
        return true;
    }
</script>
<?php
include_once(G5_MSHOP_PATH.'/_tail.php');
?>

이 질문에 댓글 쓰기 :

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

회원로그인

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