javascript confirm 질문입니다 ㅠㅠ 채택완료
위시리스트의 전체삭제 관련인데요.
</p>
<p>if (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;
}
}</p>
<p> if(confirm("정말 삭제하시겠습니까?")) {
f.act.value = act;
f.submit();
} else {
return;
}
}</p>
<p>
위의 코드인데..
confirm 박스가 뜨기전에 input들을 모두 체크해주고 싶은데
위의 코드는 컨펌박스가 없어져야 input 들이 모두 체크됩니다;
함수로 만들어도 마찬가지고
제이쿼리로 해도 마찬가지네요 ㅠ
답변 7개
왜인지는 모르겠으나
setTimeout 으로 해결했습니다..
모두모두 감사드립니다.
</p>
<p>if (act == "alldelete")
{
function all_check() {
console.log('dd');
var allInp = document.getElementsByTagName("input");
for (var i = 0, max = allInp.length; i < max; i++)
{
if(allInp[i].type === 'checkbox'){
allInp[i].checked = true;
}
}
return true;
}</p>
<p> if (all_check())
{
window.setTimeout(function(){
var result = confirm("정말 삭제하시겠습니까?");</p>
<p> if(result)
{
f.act.value = act;
f.submit();
}
else
{
var allInp = document.getElementsByTagName("input");
for (var i = 0, max = allInp.length; i < max; i++)
{
if(allInp[i].type === 'checkbox'){
allInp[i].checked = false;
}
}
return;
}
}, 100);
}
}</p>
<p>
답변에 대한 댓글 2개
댓글을 작성하려면 로그인이 필요합니다.
전역 변수로 K라는 변수 하나를 미리 선언하고 초기화 값을 0으로 넣은 다음(var k=0;)
체크박스가 전부 체크되면 K 값을 1(var k=1;)로 바꾸도록 하고
컨펌의 if문 조건에 k값이 1이 참이라면 실행,
끝나면 k값을 다시 0이되도록 세팅.
이런식으로 하면 되지 않을까요?ㅎㅎ
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
체크박스 함수의 콜백을 받아 컨펌창 실행
</p>
<p>function all_check () {
var allInp = document.getElementsByTagName("input");
for (var i=0, max=allInp.length; i <max; i++) {
if(allInp[i].type === 'checkbox'){
allInp[i].checked = true;
}
}
return true;
}
if (act == "alldelete"){
if(all_check()) {
if(confirm("정말 삭제하시겠습니까?")) {
f.act.value = act;
f.submit();
} else {
return;
}
}
}</p>
<p>
답변에 대한 댓글 1개
저도 함수만들어서 실행은 해봤는데..
왜 confirm 전에 뭐가 안되는지 모르겠네요;ㅣ
[code]
function all_check() {
var allInp = document.getElementsByTagName("input");
for (var i = 0, max = allInp.length; i < max; i++)
{
if(allInp[i].type === 'checkbox'){
allInp[i].checked = true;
}
}
return true;
}
if (act == "alldelete")
{
if (all_check())
{
if(confirm("정말 삭제하시겠습니까?"))
{
f.act.value = act;
f.submit();
}
else
{
var allInp = document.getElementsByTagName("input");
for (var i = 0, max = allInp.length; i < max; i++)
{
if(allInp[i].type === 'checkbox'){
allInp[i].checked = false;
}
}
return;
}
}
}
[/code]
댓글을 작성하려면 로그인이 필요합니다.
function fwishlist_check(f, act)에서
if (act == "alldelete") 이부분만 고쳤어요
</p>
<p>function fwishlist_check(f, act)
{
var k = 0;
var length = f.elements.length;</p>
<p> for(i=0; i<length; i++) {
if (f.elements[i].checked) {
k++;
}
}</p>
<p>
if (act == "alldelete")
{
$("input[name^=chk_it_id]").attr("checked", true);
if ($("input[name^=chk_it_id]").length == $("input[name^=chk_it_id]:checked").length)
{
if(confirm("정말 삭제하시겠습니까?")) {
f.act.value = act;
f.submit();
} else {
$("input[name^=chk_it_id]").attr("checked", false);
return;
}
}
}
else
{
if($("input[name^=chk_it_id]:checked").size() < 1) {
//var allInp = document.getElementsByTagName("input:checked");
//if(allInp.length != 0) {
alert("삭제하실 상품을 하나이상 선택해 주십시오.");
return false;
}</p>
<p> if(confirm("정말 삭제하시겠습니까?")) {
f.act.value = act;
f.submit();
} else {
return;
}
}
return true;
}</p>
<p>
답변에 대한 댓글 3개
급 죄송스럽네요;
if(confirm("정말 삭제하시겠습니까?")) { 이부분을
function 으로 따로 뺀다음에
setTimeout() 써서 시간을 좀 두고 실행시키면 될것 같은데요?
답변 감사합니다~ㅎ
댓글을 작성하려면 로그인이 필요합니다.
var i_check = 1; //for문이 돌아가면 +1
if(allInp.length == i_check){ input개수와 동일하면 실행
</p>
<p>if (act == "alldelete")
{
var i_check = 1;
var allInp = document.getElementsByTagName("input");
for (var i=0, max=allInp.length; i <max; i++)
{
if(allInp[i].type === 'checkbox'){
allInp[i].checked = true;
}
i_check++;
}
if(allInp.length == i_check){
if(confirm("정말 삭제하시겠습니까?")) {
f.act.value = act;
f.submit();
} else {
return;
}
}
}</p>
<p>
답변에 대한 댓글 4개
checkbox 만 있는건 아니라서 allInp.length == i_check 가 성립될수 없습니다;
i_check++; 이부분은 allInp.length에 다 적용됩니다.
if(allInp[i].type === 'checkbox'){ 이 안에 넣은게 아니라는거죠.
[code]
<?php
include_once('./_common.php');
if (!$is_member)
goto_url(G5_BBS_URL."/login.php?url=".urlencode(G5_SHOP_URL.'/wishlist.php'));
if (G5_IS_MOBILE) {
include_once(G5_MSHOP_PATH.'/wishlist.php');
return;
}
// 테마에 wishlist.php 있으면 include
if(defined('G5_THEME_SHOP_PATH')) {
$theme_wishlist_file = G5_THEME_SHOP_PATH.'/wishlist.php';
if(is_file($theme_wishlist_file)) {
include_once($theme_wishlist_file);
return;
unset($theme_wishlist_file);
}
}
$g5['title'] = "관심 상품";
include_once('./_head.php');
?>
<!-- 위시리스트 시작 { -->
<div id="sod_ws">
<form name="fwishlist" id="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">
<div class="tbl_head01 tbl_wrap">
<table>
<thead>
<tr>
<th scope="col">
<label for="ct_all" class="sound_only">상품 전체</label>
<input type="checkbox" name="ct_all" value="1" id="ct_all" class="chk_cus_box">
</th>
<th scope="col">번호</th>
<th scope="col">이미지</th>
<th scope="col">상품명</th>
<th scope="col">보관일시</th>
</tr>
</thead>
<tbody>
<?php
// 회원인 경우
if ($is_member){
$sql_common = " from {$g5['g5_shop_wish_table']} where mb_id = '{$member['mb_id']}' ";
} else {// 그렇지 않다면 로그인으로 가기
goto_url(G5_BBS_URL.'/login.php?url='.urlencode(G5_SHOP_URL.'/wishlist.php'));
}
// 테이블의 전체 레코드수만 얻음
$sql2 = " select count(*) as cnt " . $sql_common;
$row2 = sql_fetch($sql2);
$total_count = $row2['cnt'];
$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 ) ";
$sql .= " where a.mb_id = '{$member['mb_id']}' order by a.wi_id desc ";
$result = sql_query($sql);
$num = 0;
$num = ($page + 1) * $total_count + $i;
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);
$num--;
?>
<tr>
<td class="td_chk">
<?php
// 품절검사
if(is_soldout($row['it_id']))
{
?>
품절
<?php } else { //품절이 아니면 체크할수 있도록한다 ?>
<label for="chk_it_id_<?php echo $i; ?>" class="sound_only"><?php echo $row['it_name']; ?></label>
<input type="hidden" name="out_cd_chk" value="<?php echo $out_cd; ?>" class="chk_cus_box">
<?php } ?>
<input type="checkbox" name="chk_it_id[<?php echo $i; ?>]" value="1" id="chk_it_id_<?php echo $i; ?>">
<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">
</td>
<td class="td_num">
<?php
// 음수를 양수로
$str_num = str_replace('-','',$num);
echo $str_num;
?>
</td>
<td class="sod_ws_img"><a href="./item.php?it_id=<?php echo $row['it_id']; ?>"><?php echo $image; ?></a></td>
<td>
<a href="./item.php?it_id=<?php echo $row['it_id']; ?>">
<?php echo stripslashes($row['it_name']); ?>
<?php if(is_soldout($row['it_id'])) { // 품절검사 ?>
<span>품절</span>
<?php } ?>
</a>
</td>
<td class="td_datetime">
<?php
echo str_replace(" ", "<br>",substr($row['wi_time'],2, -3));
?>
</td>
</tr>
<?php
}
if ($i == 0)
echo '<tr><td colspan="5" class="empty_table">관심 상품이 없습니다.</td></tr>';
?>
</tr>
</tbody>
</table>
</div>
<div id="sod_ws_act">
<?php if ($i != 0) { ?>
<button type="button" class="btn_del" onclick="return fwishlist_check(document.fwishlist,'seldelete');" class="btn01">선택삭제</button>
<button type="button" class="btn_del" onclick="return fwishlist_check(document.fwishlist,'alldelete');" class="btn01" id="btnDeleteAll">전체삭제</button>
<?php } ?>
</div>
</form>
</div>
[/code]
<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")
{
var allInp = document.getElementsByTagName("input");
for (var i = 0, max = allInp.length; i < max; i++)
{
if(allInp[i].type === 'checkbox'){
allInp[i].checked = true;
}
}
if(confirm("정말 삭제하시겠습니까?")) {
f.act.value = act;
f.submit();
} else {
for (var i = 0, max = allInp.length; i < max; i++)
{
if(allInp[i].type === 'checkbox'){
allInp[i].checked = false;
}
}
return;
}
}
else
{
if($("input[name^=chk_it_id]:checked").size() < 1) {
//var allInp = document.getElementsByTagName("input:checked");
//if(allInp.length != 0) {
alert("삭제하실 상품을 하나이상 선택해 주십시오.");
return false;
}
if(confirm("정말 삭제하시겠습니까?")) {
f.act.value = act;
f.submit();
} else {
return;
}
}
return true;
}
</script>
[/code]
댓글을 작성하려면 로그인이 필요합니다.
이렇게 해도 될까요?
confirm yes면, checked 하고 submit
</p>
<p>if (act == "alldelete")
{
if(confirm("정말 삭제하시겠습니까?")) {
var allInp = document.getElementsByTagName("input");
for (var i=0, max=allInp.length; i <max; i++)
{
if(allInp[i].type === 'checkbox'){
allInp[i].checked = true;
return;
}
}</p>
<p> f.act.value = act;
f.submit();
} else {
return;
}
}</p>
<p>
답변에 대한 댓글 1개
마찬가지예요 ㅋㅋㅋ
일단 if (confirm()) {
여기 안에 코드가 들어가 있으면
confirm 값의 유무에 따라 결정되니까요
전 act 값이 alldelete 일때 실행하고 싶습니다..!
근데 웃긴게..
for는 돈다는거예요;;
console 찍어보면 찍히는게 참 ㅠㅠ
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인