채택완료

체크박스 필수로 만드는 방법

<p class="qna_privacy_agree">
                <input type="checkbox"   id="pv_agree"  name="pv_agree" class="agree_ck" />
                <label for="pv_agree" >동의합니다.</label>
            </p>

 

 

 

필수로 만드는 소스좀 알려주세요 ㅠㅠ

답변 2개 / 댓글 2개

채택된 답변
+20 포인트

<input type="checkbox" id="pv_agree" name="pv_agree" required class="agree_ck" />

 

아니면 이것도 참고하시고..

http://gnustudy.com/bbs/board.php?bo_table=skin_board&wr_id=136

답변에 대한 댓글 2개

다 적용해봐도 그냥써집니다 ㅠㅠ 다른방식은없을까요 ㅠㅠ
다 적용해봐도 그냥써집니다 ㅠㅠ 다른방식은없을까요 ㅠㅠ

예제

Copy
<form name="thisForm">
<p class="qna_privacy_agree">
                <input type="checkbox"   id="pv_agree"  name="pv_agree" class="agree_ck" />
                <label for="pv_agree" >동의합니다.</label>
            </p>

            <button type="button" onClick="chk();">확인</button>
  </form>

  <script>
    function chk() {
        var f = document.thisForm;

        if(f.pv_agree.checked!==true) {
            alert('필수항목에 체크해 주세요.');
        } else {
            alert('통과');
            f.submit();
        }
    }
  </script>

답변을 작성하려면 로그인이 필요합니다.