메뉴 건너뛰기

조회 수 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
번호 제목 날짜 조회 수
247 바닐라 JS, ECMAScript 개념 file 2023.01.20 109
246 마우스 오른쪽버튼 , 드래그 선택 차단 2023.01.12 118
245 패스워드, 확인패스워드가 맞는지 체크 2023.01.12 129
244 Node.js와 npm(+ npx)의 개념 2023.01.20 134
243 비동기 작업의 원리 (JavaScript 엔진, Web API, Task Queue, Event Loop) file 2023.01.20 138
242 개발자도구 F12키 막기 file 2023.01.12 169
241 페이지 이동 2021.03.26 190
240 getYear(); 크롬, 파이어폭스 에서 제대로 작동 안하는 문제 2021.03.26 197
239 default 매개변수(매개변수 기본값) 2021.03.26 199
238 자주쓰는 것들 2021.03.26 203
237 split, join, replace, replace_all 2021.03.26 204
236 폼안에 태그명, 함수명 같을때 오류 2021.03.26 214
235 현재 날짜, 시간 ( Month + 1 에 대해서 ) 2021.03.25 218
234 Date 객체로 원하는 날짜, 시간 표현하기 2021.08.20 223
233 Javascript - 입력한 년, 월의 마지막 날짜 구하기 2021.03.09 224
232 3자리 마다 쉼표만 찍어주는 number_format 함수 2021.03.26 225
231 오브젝트 속성 2021.03.25 237
230 월의 마지막 날짜 계산하기 2021.08.20 242
229 대소문자 변경 (대문자를 소문자로, 소문자를 대문자로) 2021.08.20 261
228 Javascript - form태그 내부 ajax처리시 2번 전송되는 현상 2021.03.09 268
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 13 Next
/ 13

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved