0
<html>
<head>
<script>
function selectCheckBox()
{   
     if(document.getElementById('id11').checked==true)
     {
     	document.frm.id2.checked=true
     	document.frm.id3.checked=true
     	document.frm.id4.checked=true
     }
     if(document.getElementById('id11').checked==false)
     {
     	document.frm.id2.checked=false
     	document.frm.id3.checked=false
     	document.frm.id4.checked=false
     }
}
function selectCheckBox1()
{
     if(document.getElementById('id12').checked==false)
     {
     	document.frm.id1.checked=false
     }  
}
function selectCheckBox2()
{
     if(document.getElementById('id13').checked==false)
     {
     	document.frm.id1.checked=false
     }  
}
function selectCheckBox3()
{
     if(document.getElementById('id14').checked==false)
     {
     	document.frm.id1.checked=false
     }  
}
</script>

</head>
<body>
<form name="frm">
All   :<input type="checkbox" id="id11" name="id1" value="1" onClick="selectCheckBox()"><br>
A.    :<input type="checkbox" id="id12" name="id2" value="2" onClick="selectCheckBox1()"><br>
B.    :<input type="checkbox" id="id13" name="id3" value="3" onClick="selectCheckBox2()"><br>
C.    :<input type="checkbox" id="id14" name="id4" value="4" onClick="selectCheckBox3()"><br>
</form>
</body>
</html>

Edited by __avd: Added [code] tags.

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by javaAddict
0

You don't need the selectCheckBox1,2,3. When the check box is clicked, it is checked automatically.
Also there is no problem in having the name and id attributes having the same value. In some cases you need them to have different values but they can also have the same.

Also what problems do you get? The code seems ok.

Also it is better to replace the document.frm.id2.checked=true with document.getElementById("id12").checked=true Do you have any errors? If the code doesn't work, you should try adding ';' at the end of each command, like in java:

document.frm.id2.checked=true;
document.frm.id3.checked=true;
document.frm.id4.checked=true;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.