Six radio choices, each with three check boxes, after selecting one of them, only the corresponding three check boxes can be selected. , And if another radio is selected again, the check boxes that can be selected are changed accordingly.
function radioClick(radio){
The
if(radio=="radio1"){
The
var checks=document.getElementsByName("checkbox1");
for(i=0;i<checks.length;i++){
The
checks[i].disabled=null;
}
var checks=document.getElementsByName("checkbox2");
for(i=0;i<checks.length;i++){
The
checks[i].disabled=true;
}
}
else if(radio=="radio2"){
alert("ff");
var checks=document.getElementsByName("checkbox2");
for(i=0;i<checks.length;i++){
The
checks[i].disabled=null;
}
var checks=document.getElementsByName("checkbox1");
for(i=0;i<checks.length;i++){
The
checks[i].disabled=true;
}
}
The
}
</script>
</head>
I’ll give you one. I’m looping through this. Be careful when naming the checkbox.
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<SCRIPT LANGUAGE="JavaScript">
function check(){
var radio=document.getElementsByName('radio');
for(flag=0;flag<radio.length;flag++)
{
if(radio[flag].checked){
var res = "chk"+flag;
var checkbox = document.getElementsByName(res);
for(i=0;i<checkbox.length;i++)
{
checkbox[i].checked=true;
checkbox[i].disabled = false;
}
}
else
{
var res = "chk"+flag;
var checkbox = document.getElementsByName(res);
for(i=0;i<checkbox.length;i++)
{
checkbox[i].checked=false;
checkbox[i].disabled =true;
}
}
}
}
</SCRIPT>
</HEAD>
<BODY>
<INPUT type="radio" name="radio" onclick=check() />
<!--
The checkboxes are all chk plus the index of the radio box they belong to
For example here
The radio box is a radio group with an index of 0; so the checkbox is called chk0
The same is true below
-->
<INPUT type="checkbox" name="chk0">
<INPUT type="checkbox" name="chk0">
<INPUT type="checkbox" name="chk0">
<br>
<INPUT type="radio" name="radio" onclick=check() />
<INPUT type="checkbox" name="chk1">
<INPUT type="checkbox" name="chk1">
<INPUT type="checkbox" name="chk1">
<br>
<INPUT type="radio" name="radio" onclick=check() />
<INPUT type="checkbox" name="chk2">
<INPUT type="checkbox" name="chk2">
<INPUT type="checkbox" name="chk2">
<br>
<INPUT type="radio" name="radio" onclick=check() />
<INPUT type="checkbox" name="chk3">
<INPUT type="checkbox" name="chk3">
<INPUT type="checkbox" name="chk3">
<br>
<INPUT type="radio" name="radio" onclick=check() />
<INPUT type="checkbox" name="chk4">
<INPUT type="checkbox" name="chk4">
<INPUT type="checkbox" name="chk4">
<br>
<INPUT type="radio" name="radio" onclick=check() />
<INPUT type="checkbox" name="chk5">
<INPUT type="checkbox" name="chk5">
<INPUT type="checkbox" name="chk5">
<br>
</BODY>
</HTML>