본문 바로가기

spring/게시판 만들기

[spring] 스프링 게시판 checkbox 체크되었을 때 1, 안되었을 때 0 표현

고정게시물의 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>

 

 

<참고자료>

https://stackoverflow.com/questions/31367098/how-to-submit-0-if-checkbox-is-unchecked-and-submit-1-if-checkbox-is-checked-in

 

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

 

반응형