메뉴 건너뛰기

조회 수 19010 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부
<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>check박스 체크 여부 확인하기</title>
 
  <script type="text/javascript">
    function CheckForm(Join){
        
        //체크박스 체크여부 확인 [하나]
        var chk1=document.frmJoin.U_checkAgreement1.checked;
        var chk2=document.frmJoin.U_checkAgreement2.checked;
        
        if(!chk1){
            alert('약관1에 동의해 주세요');
            return false;
        } 
        if(!chk2) {
            alert('약관2에 동의해 주세요');
            return false;
        }

        //체크박스 체크여부 확인 [동일 이름을 가진 체크박스 여러개일 경우]
        var isSeasonChk = false;
        var arr_Season = document.getElementsByName("SEASON[]");
        for(var i=0;i<arr_Season.length;i++){
            if(arr_Season[i].checked == true) {
                isSeasonChk = true;
                break;
            }
        }
    
        if(!isSeasonChk){
            alert("계절의 종류를 한개 이상 선택해주세요.");
            return false;
        }

    }


 </script>
 </head>
 <body>
 
  
<form name="frmJoin" action=""  onSubmit="return CheckForm(this)">
    <input type="checkbox" name="U_checkAgreement1" id="U_checkAgreement1" value="" /> 약관동의
    <input type="checkbox" name="U_checkAgreement2" id="U_checkAgreement2" value="" /> 약관동의

    <br/>
    <br/>
    <input type="checkbox" id="spring" name="SEASON[]" value="1" />
    <input type="checkbox" id="summer" name="SEASON[]" value="2" />여름
    <input type="checkbox" id="fall" name="SEASON[]" value="3" />가을
    <input type="checkbox" id="windter" name="SEASON[]" value="4" />겨울
    <br/>
    <br/>
    <input type="submit" value="전송">
</form>

 </body>
</html>

 



 

 

 

jQuery로 변경


 [코드]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
        //체크박스 체크여부 확인 [동일 이름을 가진 체크박스 여러개일 경우]
        /*var isSeasonChk = false;
        var arr_Season = document.getElementsByName("SEASON[]");
        for(var i=0;i<arr_Season.length;i++){
            if(arr_Season[i].checked == true) {
                isSeasonChk = true;
                break;
            }
        }*/

        
        //jQuery로 변경
        var isSeasonChk = $("input:checkbox[name='SEASON[]']").is(":checked");
    
        if(!isSeasonChk){
            alert("계절의 종류를 한개 이상 선택해주세요.");
            return false;
        }

 

 

 



List of Articles
번호 제목 날짜 조회 수
187 이클립스 실행할때 자신이 원하는 JDK 지정하는 방법 file 2016.09.11 5439
186 이전, 위로 이동 2016.12.23 5740
185 이벤트 - 페이지 로드 후 이벤트 처리하기 ( window.onload ) file 2015.06.19 10871
184 이미지클릭시 옆에 큰이미지나오기 2014.03.17 5518
183 이미지에 마우스 올렸을때 확대 이미지 나오게 하기 (onmouseover 2014.03.01 6923
182 이미지나 태그정렬이 안맞을때 absmiddle 2014.03.01 5238
181 이미지 마우스 드래그로 스크롤을 움직이는 소스 2014.03.17 9361
180 이메일 체크하기 2014.03.01 5205
179 이동 가능한 레이어팝업 소스 2016.09.01 7166
178 유효한 링크인지 확인하는 JAVASCRIPT 2019.01.16 111981
177 유효성 검사, 모든 폼에 값이 입력되도록 해보자! file 2015.02.03 6123
176 유용한 스크립트 모음 2018.07.24 2294
175 월의 마지막 날짜 계산하기 2021.08.20 242
174 우클릭 금지 2016.12.23 5701
173 오브젝트 속성 2021.03.25 237
172 오늘 날짜 구하기 2018.11.07 1416
171 예제 - 자바스크립트로 현재 달의 달력 만들기 (calendar) 2015.06.19 10061
170 예제 - 이미지를 원본 크기로 볼 수 있도록 새창으로 열기 확장 (리사이징 및 이미지 드래그) file 2015.06.19 6798
169 영문, 숫자, 한글, 이메일 체크 하는 함수 2014.03.01 5292
168 연관배열 사용하기 2016.09.21 7134
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 13 Next
/ 13

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved