Code:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>123</title>
<style type="text/css">
body{text-align:center;font-family:Verdana,Arial;font-size:11px;background-color:#fff;color:#000;padding:0px;margin:15% 0px 0px 0px;}
input[type="checkbox"]{margin-left:10px;}
label{font-weight:bold;font-style:italic;}
</style>
<script type="text/javascript">
/* array for the checkboxes */
var cbx=[];
function init(){
/* all INPUTS in the form */
var inps=document.getElementById('myform').getElementsByTagName('INPUT');
/* this loop goes through all INPUTS */
for(var i in inps){
/* if the current is not a checkbox, the loops skips it and goes further */
if(inps[i].type!='checkbox'){continue;}
else{
/* if the current is a checkbox, it is stored in the cbx array */
cbx.push(inps[i]);
/* when a checkbox is clicked */
inps[i].onclick=function(){
/* if it was unchecked, the function does nothing */
if(!this.checked){return;}
/* if it was checked the function loops through the cbx array */
else{for(var k in cbx){
/* if the current array's member is the checkbox which has been clicked, the loops skips it */
if(cbx[k]===this){continue;}
/* if it is another checkbox, it is getting unchecked */
else{cbx[k].checked=false;}
}
}
}
}
}
}
window.onload=init;
</script>
</head>
<body>
<form name="myform" id="myform" action="">
<label for="cb_1">Checkbox 1</label><input type="checkbox" name="cb_1" id="cb_1" /><br />
<label for="cb_2">Checkbox 2</label><input type="checkbox" name="cb_2" id="cb_2" /><br />
<label for="cb_3">Checkbox 3</label><input type="checkbox" name="cb_3" id="cb_3" /><br />
<label for="cb_4">Checkbox 4</label><input type="checkbox" name="cb_4" id="cb_4" /><br />
<label for="cb_5">Checkbox 5</label><input type="checkbox" name="cb_5" id="cb_5" />
</form>
</body>
</html>
Bookmarks