고정게시물의 checkbox가 체크되었을 때 1, 안되었을 때 0을 표현해주고 싶었다.
우선 jsp에 다음과 같이 코드를 작성해주었다.
memberLevel이 0일 경우(=관리자), 고정글이 나오게 조건을 넣어주었고
javascript를 작성하여 체크박스를 체크했을 때는 1, 체크하지 않았을 때는 0이 전송될 수 있도록 하였다.
board.jsp
<c:if test="${sessionScope.m.memberLevel eq 0 }">
<tr>
<th>고정글</th>
<td>
<input type="checkbox" name="priority" value='1' id="check">
<input type="hidden" name="priority" value='0' id="check_hidden"/>
</td>
</tr>
</c:if>
<script>
if(document.getElementById("check").checked) {
document.getElementById("check_hidden").disabled = true;
}
</script>
<참고자료>
How to submit 0 if checkbox is unchecked and submit 1 if checkbox is checked in HTML
How to submit value 1 if a checkbox in a checkbox array is checked, and submit 0 if it's unchecked? I tried this but no luck. I am trying to grab this array in a php array when the form is submitted.
stackoverflow.com
반응형
'spring > 게시판 만들기' 카테고리의 다른 글
[spring] 게시판 주제별 검색기능 구현 (0) | 2022.03.01 |
---|---|
[spring] 게시판 이전화면/수정하기/삭제하기 (0) | 2022.02.19 |
[spring] 스프링게시판 페이징(paging) 처리 (0) | 2022.02.18 |
[spring/mybatis] 게시판 조회수 (0) | 2022.02.16 |
[spring/mybatis] 게시판 리스트 출력 (0) | 2022.02.15 |