update 여부 검증

기여·2024년 6월 30일
0

소소한 개발팁

목록 보기
47/103

상태 안 바꾸고 실수로 '변경' 버튼 눌렀을 경우 대비해, 아래 경고창 띄우고

변경 처리하기 전에 한 번 더 묻고 서버로 넘어가기~

예제:

<form id="statusForm<%= od.getOrderRef() %>" action="<%=path%>/CardCtrl" method="get">
			
			<select class="selectStatus"  id="orderStatus<%= od.getOrderRef() %>" name="orderStatus">
			      <option value="<%= od.getOrderStatus() %>"><%= od.getOrderStatus() %></option>
			      <option value="접수">접수</option>
			      <option value="심사">심사</option>
			      <option value="승인">승인</option>
			      <option value="반려">반려</option>
			      <option value="거절">거절</option>
			 	</select>
			 	
				<input type="hidden" name="sw" value="changeOrderStatus">
				<input type="hidden" name="orderRef" value="<%= od.getOrderRef() %>">
				<input type="hidden" id="currentStatus<%= od.getOrderRef() %>" value="<%= od.getOrderStatus() %>">
</form>
            
<button class="button" onclick="changeConfirm(<%= od.getOrderRef() %>)">변경</button>	
<script>
function changeConfirm(orderRef) {
    var selectedStatus = document.getElementById('orderStatus' + orderRef).value;
    var currentStatus = document.getElementById('currentStatus' + orderRef).value;
    if (selectedStatus === currentStatus) {
        alert('변경사항이 없습니다. 다시 확인해 주세요.');
        return false;
    }
    if (confirm('해당 주문건 상태를 변경하시겠습니까?')) {
        document.getElementById('statusForm' + orderRef).submit();
    }
    return false;
}
</script>
profile
기기 좋아하는 여자

0개의 댓글