select all check boxes using javascript

Posted by Ankitsrist under ASP.NET on 3/18/2013 | Points: 10 | Views : 1222 | Status : [Member] | Replies : 9
helo,
i want to select all checkboxes by using javascript my code is as follows
 <script language ="javascript" type="text/javascript">
function checkbox1(chcontrol, state)
{
var chkbx1=document.getElementById(chcontrol);
var chkBoxCount=chkbx1.getElementsByTagName("input");
for(var i=0;i<chkBoxCount.length;i++)
{
chkBoxCount[i].checked = state;
}
return false;
}
</script>

 select<a id="chk1" href="#" onclick="javascript:checkbox1('<%=CheckBoxList1.ClientID%>', true)">All</a>|<a id="chk2" href="#" onclick="javascript:checkbox1('<%=CheckBoxList1.ClientID%>', false)">None</a>

this code is working fine with anchor tags when i call my function from this tag,
but it is not working when i call the javascript function from checkbox like in this way <asp:CheckBox ID="CheckBox1" runat="server" Text="Select All" oncheckedchanged="javascript:checkbox1('<%=CheckBoxList1.ClientID%>', true)" /><br />

please help




Responses

Posted by: Jayakumars on: 3/18/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

refer this url

http://stackoverflow.com/questions/6297733/checkboxlist-check-functionality

Mark as Answer if its helpful to you

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 3/18/2013 [Member] Starter | Points: 25

Up
0
Down
thanks actualy javascript function is not the problem but calling of this function creating problem i think

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 3/18/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
check this code working Good. Put that Array Index.


<script language ="javascript" type="text/javascript">
function checkbox1(chcontrol, state) {

var chkbx1 = document.getElementById(chcontrol);
var chkBoxCount = chkbx1.getElementsByTagName("input");
for (var i = 0; i < chkBoxCount.length; i++) {
chkBoxCount[i].checked = state;
}
return false;
}





</script>

mark as answer if it is useful.


Mark as Answer if its helpful to you

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 3/18/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
<script language ="javascript" type="text/javascript">
function checkbox1(chcontrol, state) {

var chkbx1 = document.getElementById(chcontrol);
var chkBoxCount = chkbx1.getElementsByTagName("input");
for (var i = 0; i < chkBoxCount.length; i++) {
chkBoxCount[i].checked = state;
}
return false;
}





</script>

Mark as Answer if its helpful to you

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 3/18/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

put this my code did not copied here.

chkBoxCount[i].checked = state;

Mark as Answer if its helpful to you

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 3/18/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
try this
checkboxCount[i].checked=state;

Mark as Answer if its helpful to you

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 3/18/2013 [Member] Starter | Points: 25

Up
0
Down
mine and ur code both are identical

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 3/18/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
try this code

<asp:CheckBox ID="CheckBox1" runat="server" Text="Select All" onchange="javascript:checkbox1('CheckBoxList1', true);" />

Mark as Answer if its helpful to you

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 3/18/2013 [Member] Starter | Points: 25

Up
0
Down
help will be highly appreciated... anyone there to get me rid from this :)

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response