자바스크립트 부분
<script type="text/javascript">
<!--
function allCk(objCheck){ //전체 선택 checkbox 클릭
var checks = document.getElementsByName('cp_no');
for( var i = 0; i < checks.length; i++ ){
checks[i].checked = objCheck;
checks[i].checked = objCheck;
// name이 'cp_no' 인 checkbox는 id가 allck인 checkbox의 checked 상태와 같게 된다.
}
}
function deleteGo(){ //여러 게시물을 선택하고 삭제하기
function deleteGo(){ //여러 게시물을 선택하고 삭제하기
var listForm = document.getElementById("listForm");
listForm.action = "../cafe/cafeDelete.jsp?blc_no=<%=blc_no%>";
listForm.submit();
listForm.action = "../cafe/cafeDelete.jsp?blc_no=<%=blc_no%>";
listForm.submit();
}
//-->
</script>
jsp 부분
<form name="listForm" id="listForm" action="" method="post">
<input type="checkbox" id="allck" name="allck" onclick="allCk(this.checked);">
<%
//-->
</script>
jsp 부분
<form name="listForm" id="listForm" action="" method="post">
<input type="checkbox" id="allck" name="allck" onclick="allCk(this.checked);">
<%
int vectorSize = 5;
for( int i=0; i<vectorSize; i++ ){
for( int i=0; i<vectorSize; i++ ){
%>
<input type="checkbox" name="cp_no" value="<%=(i+1)%>" >
<%
<input type="checkbox" name="cp_no" value="<%=(i+1)%>" >
<%
}
%>
<a href="#" onclick="deleteGo(); return false;"><img src="../files/images/boardCafe/btn_remove.gif" alt="삭제" /></a>
</form>
java 부분
String[] cp_no = getParameterValues("cp_no");
String whereStr = "";
//getParameterValues를 이용 배열로 받는다.
<a href="#" onclick="deleteGo(); return false;"><img src="../files/images/boardCafe/btn_remove.gif" alt="삭제" /></a>
</form>
java 부분
String[] cp_no = getParameterValues("cp_no");
String whereStr = "";
//getParameterValues를 이용 배열로 받는다.
if( cp_no.length != 0 ){
whereStr = " and cp_no in ( "; // in(or)이용
whereStr = " and cp_no in ( "; // in(or)이용
for( int i=0; i<cp_no.length; i++ ){ //배열의 길이만큼 for문으로 돌린다
whereStr += cp_no[i];
if( i != (cp_no.length-1) ){
whereStr += " , ";
}
}
whereStr += " ) ";
}
buffer.append(" UPDATE TBLCAFEPOST SET ")
buffer.append(" UPDATE TBLCAFEPOST SET ")
.append(" CP_ISDELETE = 'Y'")
.append(" where blc_no = ").append(utilBean.convertDB(getParameter("blc_no")))
.append(" where blc_no = ").append(utilBean.convertDB(getParameter("blc_no")))
append(whereStr);
query = buffer.toString();
buffer.delete(0, buffer.length());
iAffected = stmt.executeUpdate(query);
if ( iAffected != 1 ) {
throw new SQLException("ERROR! " + iAffected + " rows effected, QUERY : " + query);
} else {
htReturn.put("isOK", "Y"); //Hashtable에 성공 여부 저장
}
query = buffer.toString();
buffer.delete(0, buffer.length());
iAffected = stmt.executeUpdate(query);
if ( iAffected != 1 ) {
throw new SQLException("ERROR! " + iAffected + " rows effected, QUERY : " + query);
} else {
htReturn.put("isOK", "Y"); //Hashtable에 성공 여부 저장
}