본문 바로가기

[Terry] ETC

체크박스 제어해보자…

웹을 하면서 HTML의 폼태그들은 다양하게 사용된다.

오늘은 그중 checkbox를 제어하는 스크립트를 올려본다.

체크박스를 체크하면 텍스트창이 활성화 되는 HTML이다.

<html>
<head>
    <title>::: checkbox 제어 :::</title>

    <script language="JavaScript">
        function change_pwd(objCheck){
         var count = 0;
          if(objCheck.name!=undefined) {
            if (objCheck.checked ==true)
            {
                count=1;
                document.frm_2.interlocked_pass.disabled = false;
                document.frm_2.passwd_set.value = 1;
             }
          }else{
            for (i=0; i<objCheck.length; i++) {
              if (objCheck[i].checked == true) {
                   count=count+1;
                   break;
                }
             }
           }
           if (count==0){
               document.frm_2.interlocked_pass.disabled = true;
               document.frm_2.passwd_set.value = 0;
           } else {
               return true;
           }
        }
    </script>
</head>

<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">
<form name="frm_2">
    <table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
        <tr height="21">
            <td >활성화.. <font color="red"></font></td>
            <td  style="padding-left:5px">
                <input type="text" name="interlocked_id" size="20" maxlength="20" value="" disabled>&nbsp;                                   
            </td>           
        </tr>   
        <tr height="21">
            <td >비활성화 <font color="red"></font></td>
            <td style="padding-left:5px">           
                <input type="text" name="interlocked_pass" size="20" maxlength="20" value="aaa" disabled>
                <input type="checkbox" name="passwd_set" border="0" value="0" onclick="javascript:change_pwd(this);">활성화 시키려면 체크하세요.
            </td>
        </tr>   
    </table>                       
</form>

</body>
</html>

Tistory 태그: