checkbox, radio, textarea 구분해서 입력여부 판단 > script

본문 바로가기

script

checkbox, radio, textarea 구분해서 입력여부 판단

작성일 07-10-17 17:39

페이지 정보

작성자서방님 조회 124회 댓글 0건

본문

<script type="text/javascript">
var total = 3; // 문제 수를 미리 받아옴

function check(form) {
    for(var i=1 ; i<total+1 ; i++) {
        var question = form["a"+i]?form["a"+i]:form["a"+i+"[]"];
        var answer = false;
        if(len = question.length) {
            for(var j=0 ; j<len ; j++) {
                if(question[j].checked) {
                    answer = true;
                    break;
                }
            }
        } else {
            if(question.value)
                answer = true;
        }

        if(!answer)
            alert(i+"번 문항을 확인하세요.");
    }
}
</script>

</head>

<body>
<form name="test" method="post">
    <input type="radio" name="a1" />
    <input type="radio" name="a1" />
    <input type="checkbox" name="a2[]" />
    <input type="checkbox" name="a2[]" />
    <textarea name="a3" /></textarea>
    <input type="button" value="check" onclick="check(this.form)" />
</form>

댓글목록

등록된 댓글이 없습니다.

전체 846건 24 페이지
게시물 검색
Copyright © 서방님.kr All rights reserved.
PC 버전으로 보기