Copy
<?php
$result = sql_fetch(" select count(*) as cnt from $write_table where wr_is_comment='1' and wr_parent='$view[wr_id]' and mb_id='$member[mb_id]'");
if($result['cnt']<"1") {
?>
<div class="res_btn">신청서 작성</button>
<?php } ?>
이미 댓글을 달았을 때 버튼이 안보이는게 아니라
이미 댓글을 달았다면 버튼 클릭시 alert 창이 보이게 하고싶은데 어떻게 해야할까요?
|
답변 1개 / 댓글 3개
채택된 답변
+20 포인트
4년 전
Copy
<?php
$result = sql_fetch(" select count(*) as cnt from $write_table where wr_is_comment='1' and wr_parent='$view[wr_id]' and mb_id='$member[mb_id]'");
$addEvent = ($result['cnt'] > 0) ? 'onclick="alert(\'신청서를 이미작성하셨습니다.\'); event.stopPropagation();"' : '';
?>
<div class="res_btn" <?php echo $addEvent; ?>>신청서 작성</button>
답변에 대한 댓글 3개
4년 전
감사합니다 필립스님! 경고창은 잘 뜨는데 경고창 뜨고 바로 신청서 작성하는 폼이 나와버리는데 신청서 작성폼이 동작 안하게 제어까리 해주려면 어떻게 해야하나요?
Phillips
4년 전
<?php
$result = sql_fetch(" select count(*) as cnt from $write_table where wr_is_comment='1' and wr_parent='$view[wr_id]' and mb_id='$member[mb_id]'");
$addEvent = ($result['cnt'] > 0) ? 'onclick="alert(\'신청서를 이미작성하셨습니다.\'); return false;"' : '';
?>
<div class="res_btn" <?php echo $addEvent; ?>>신청서 작성</button>
$result = sql_fetch(" select count(*) as cnt from $write_table where wr_is_comment='1' and wr_parent='$view[wr_id]' and mb_id='$member[mb_id]'");
$addEvent = ($result['cnt'] > 0) ? 'onclick="alert(\'신청서를 이미작성하셨습니다.\'); return false;"' : '';
?>
<div class="res_btn" <?php echo $addEvent; ?>>신청서 작성</button>
4년 전
필립스님 감사합니다. 해결하였습니다! php에 대해 잘 몰라서 제가 알고있는 jquery와 필립스님이 말씀해주신 것으로 응용해서 해보니 잘 되네요!
<?php
$result = sql_fetch(" select count(*) as cnt from $write_table where wr_is_comment='1' and wr_parent='$view[wr_id]' and mb_id='$member[mb_id]'");
$addEvent = ($result['cnt'] > 0) ? 'onclick="res_notice()"' : '' ;
?>
<div class="res_btn" <?php echo $addEvent; ?> style="cursor:pointer;">신청서 작성</button>
<?php } ?>
이런식으로 jquery 스크립트를 받아와 기존 버튼의 클릭 이벤트를 날려주고 다시 새로고침하여, 버튼의 기능을 다시 살려주었습니다.
function res_notice() {
alert("이미 신청서를 작성하셨습니다. 신청이 반려되었을 경우 삭제 후 다시 신청해주세요.");
$(".res_btn").attr('onclick', '').unbind('click');
window.location.reload();
}
<?php
$result = sql_fetch(" select count(*) as cnt from $write_table where wr_is_comment='1' and wr_parent='$view[wr_id]' and mb_id='$member[mb_id]'");
$addEvent = ($result['cnt'] > 0) ? 'onclick="res_notice()"' : '' ;
?>
<div class="res_btn" <?php echo $addEvent; ?> style="cursor:pointer;">신청서 작성</button>
<?php } ?>
이런식으로 jquery 스크립트를 받아와 기존 버튼의 클릭 이벤트를 날려주고 다시 새로고침하여, 버튼의 기능을 다시 살려주었습니다.
function res_notice() {
alert("이미 신청서를 작성하셨습니다. 신청이 반려되었을 경우 삭제 후 다시 신청해주세요.");
$(".res_btn").attr('onclick', '').unbind('click');
window.location.reload();
}
답변을 작성하려면 로그인이 필요합니다.