메뉴 건너뛰기

조회 수 19033 추천 수 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
번호 제목 날짜 조회 수
227 Javascript - 입력받은 숫자를 순서대로 홀짝 별로 배열에 삽입하기 2021.03.09 321
226 자바스크립트에서 이벤트 중단 하는 방법 2021.03.25 339
225 javascript - vanillaJS로 체크박스(checkbox) 제어하기 file 2021.03.09 516
224 Javascript - Calendar 달력 생성하고 제어하기 2021.03.09 530
223 HTML, Javscript - 선택한 색상으로 배경색 바꾸기(pallet 만들기) file 2021.03.09 736
222 Javascript - 유효성 체크(이메일 정규식, IP 정규식, 비밀번호 등) 2021.03.09 747
221 Javascript - Free SVG 한국맵 제어 처리 file 2021.03.09 892
220 DTREE 트리구조 만들기 file 2021.03.26 899
219 팝업창 맨위로 올라오게 하기 2021.03.26 910
218 ajax 사용시 Internal Sever Error 뜨는 경우 2021.03.26 985
217 배열과 Array객체 2019.01.16 1068
216 에러처리 2019.01.16 1078
215 Javascript - 사업자 등록번호 유효성 체크 file 2021.03.09 1102
214 input 태그에서 name과 id의 차이 2019.01.16 1130
213 기간 설정용 달력 팁앤노하우 2019.01.16 1147
212 풍선도움말 2019.01.16 1179
211 한글 또는 영문만이 존재하는지 체크 2019.01.16 1181
210 한글 짜르기 2019.01.16 1195
209 랜덤(Random) / 난수 만들기 2019.01.16 1200
208 두 날짜 사이 토일요일 개수 구하기 2019.01.16 1269
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 13 Next
/ 13

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved