메뉴 건너뛰기

조회 수 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 5초 후에 해당페이지로 url 옮기기 2014.02.27 10485
246 자바스크립트 개체 복사 2014.02.27 6573
245 마우스를 오버해서 이미지를 확대해서 보기 2014.02.27 7003
244 적용이 간편한 [글목록 인쇄] 등 특정 영역 인쇄하기 팁 2014.02.27 6285
243 미디어플레이어 화면크기 조절방법 2014.02.27 6366
242 깔끔한 이미지로 2014.02.27 6260
241 지금 보고 있는 웹페이지 창을 닫으려고 합니다." 안나타나게 하기 2014.02.27 7185
240 라디오 버튼 value 값 있는지 체크하기 2014.02.27 6336
239 textarea의 글자수 제한 2014.02.27 6161
238 input 박스에서 유용한 자바 스크립트 2014.02.27 5462
237 3자리마다 콤마찍기 2014.02.27 5756
236 적용이 간편한 [글목록 인쇄] 등 특정 영역 인쇄하기 팁 2014.02.27 5441
235 iframe 아이프레임 내용 길이에 따라서 높이가 자동으로 조절 되도록 2014.02.27 6206
234 차단된 팝업창을 허용하라는 스크립트 2014.02.27 6751
233 JavaScript 날짜관련함수 2014.02.27 5704
232 날짜 간의 일수 계산 2014.02.27 7551
231 네이버 달력 자바스크립트 소스 2014.02.27 6329
230 이미지에 마우스 올렸을때 확대 이미지 나오게 하기 (onmouseover 2014.03.01 6923
229 주민번호 입력시 생일 자동입력 file 2014.03.01 5621
228 input 테그안의 숫자 3자리 마다 콤마 찍기 2014.03.01 6077
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 13 Next
/ 13

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved