Hi Every One,
I struggled a little to check and uncheck all on checkbox click today. At last i found a bit of code to do it by my friend.
Here is the script i used,
<script type="text/javascript">
function checkedAll (obj)
{
var aa= document.getElementsByName(obj.id);
if (obj.checked){
var i =0;
while(i<aa.length)
{
aa[i].checked=true;
i++;
}
}
else {
var i =0;
while(i<aa.length)
{
aa[i].checked=false;
i++;
}
}
}
</script>
Form Coding:
<form method="post">
<div id="c">
<div id="a" >
<input type="checkbox" name="a" id="agroup" onclick="checkedAll(this)"/>Header1<br />
<input type="checkbox" name="agroup" />List A1
<input type="checkbox" name="agroup" />List A2
</div>
<br />
<br />
<div id="b">
<input type="checkbox" name="b" id="bgroup" onclick="checkedAll(this)"/>Header2<br />
<input type="checkbox" name="bgroup" />List A1
<input type="checkbox" name="bgroup" />List A2
</div>
</div>
</form>
But i am trying to make it by Id. Let me think of it.
~umar
I struggled a little to check and uncheck all on checkbox click today. At last i found a bit of code to do it by my friend.
Here is the script i used,
<script type="text/javascript">
function checkedAll (obj)
{
var aa= document.getElementsByName(obj.id);
if (obj.checked){
var i =0;
while(i<aa.length)
{
aa[i].checked=true;
i++;
}
}
else {
var i =0;
while(i<aa.length)
{
aa[i].checked=false;
i++;
}
}
}
</script>
Form Coding:
<form method="post">
<div id="c">
<div id="a" >
<input type="checkbox" name="a" id="agroup" onclick="checkedAll(this)"/>Header1<br />
<input type="checkbox" name="agroup" />List A1
<input type="checkbox" name="agroup" />List A2
</div>
<br />
<br />
<div id="b">
<input type="checkbox" name="b" id="bgroup" onclick="checkedAll(this)"/>Header2<br />
<input type="checkbox" name="bgroup" />List A1
<input type="checkbox" name="bgroup" />List A2
</div>
</div>
</form>
But i am trying to make it by Id. Let me think of it.
~umar
No comments:
Post a Comment