본문 바로가기
📚 개발 공부

[Javascript ] Select 박스안에 check박스 넣기

by cheonvi 2011. 9. 17.


HTML에서는 셀렉트 박스안에 체크 박스를 넣는것은 없다

하지만, 그렇게 보일도록 구현 하면 된다.
<예제>

<html>
<head>
<script>
function test(value) {
if(value==1) Div.style.visibility = 'visible';
else Div.style.visibility = 'hidden';

if(value ==2){
 
 var frm = document.forms[0];
 frm.aaa.value="";
 if(frm.chk1.checked == true)
  frm.aaa.value = frm.chk1.value;
}
}
</script>
</head>
<body>
<form name="form1">
<table cellpadding="0" cellspacing="0" style="cursor:hand" onClick="test(1)">
<tr>
<td align="center" width="120" height="20" style='border:1px solid;font-size:12'>
<input type="text" name="aaa" size="15" value="">
</td>
<td height=20 style='border:1px solid;cursor:hand'>
<img src='http://file.danawa.co.kr/all_images/comindex_left_check.gif' border="0"></td>
</tr>
</table>
<div id='Div' style="width=120;height:50;position:absolute;visibility:hidden;border:1 solid">
<input type="checkbox" name="chk1" value="checkbox1">checkbox1<br>
<input type="checkbox" name="chk2" value="checkbox2">checkbox2<br>
<input type="button" value="확인" onClick="test(2)">
</div>
</form>
</body>
<html>

구글에서 검색하여 조금 수정 하였다.

출처