본문 바로가기
Developer/Javascript & jQuery

[Javascript] Checkbox로 Selectbox제어

by 순수한소년 2017. 1. 7.
728x90
반응형

개씨발체크박스

 

@

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" trimDirectiveWhitespaces="true"%>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Insert title here</title>
</head>
 
<body>
    <form name="frm" id="frm" method="post" enctype="multipart/form-data">
        <select name="status" id="status" class="link" title="" style="width: 80px;">
            <option value="" ${codeModel.codeStr == '' ? 'selected="selected"' : ''}>상태</option>
            <c:forEach var="codeModel" items="${modelComCodeList}" varStatus="stat">
                <option value="${codeModel.codeStr}" ${codeModel.codeStr == param.status ? 'selected="selected"' : ''}>${codeModel.codeName}</option>
            </c:forEach>
        </select>
        <input type="checkbox" name="searchRegYn" id="searchRegYn" value="on" ${param.searchRegYn == 'on' ? 'checked' : ''} onchange="f_change()" />
    </form>
<!-- /* javascript ################################################## S */ -->
<script type="text/javascript">
//<![CDATA[
    window.onload = function () {
 
    var readyRegYn = searchRegYn.value;        //상태 Ready
 
    if (readyRegYn == 'on') {
            console.log("체크박스 > 설정");
            console.log(status);
            status.disabled = true;
        } else {
            console.log("체크박스 > 해제");
            status.disabled = false;
        }
    }
    function f_change() {//         alert(searchRegYn);
        var status = document.getElementById("status");
        var searchRegYn = document.getElementById("searchRegYn");
        console.log(searchRegYn);
        if (searchRegYn.checked == true) {
            console.log("체크박스> 설정");
            console.log(status);
            status.disabled = true;
        } else {
            console.log("체크박스 > 해제");
            status.disabled = false;
        }
    }
//]]>
</script>
<!-- /* javascript ################################################## E */ -->
</body>
</html>
cs

@

728x90
반응형