how to select all chkboxes by selecting one in javascript

Posted by Shanky11 under JavaScript on 2/28/2013 | Points: 10 | Views : 796 | Status : [Member] | Replies : 2
i have a chkbox in header secton of griedview i want that when i click on header section ckh box shoul get selected.




Responses

Posted by: Raj.Trivedi on: 2/28/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hello Shanky11,

http://www.aspdotnet-suresh.com/2012/09/check-uncheck-all-checkboxes-in.html

Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

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

Posted by: Kusumas on: 3/1/2013 [Member] Starter | Points: 25

Up
0
Down
This is for Select All check boxes

function CheckAll(obj) {
var grid = document.getElementById('<%= gv1.ClientID %>');
var inputs = grid.getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].type == "checkbox") {
if (obj.checked)
inputs[i].checked = true;
else
inputs[i].checked = false;
}
}
}


This is for UnSelect All check boxes

function CheckUnCheck(obj) {
var grid = document.getElementById('<%= gv1.ClientID %>');
var inputList = grid.getElementsByTagName("input");
var checkedval = true;
for (var i = 1; i < inputList.length; i++) {
if (inputList[i].type == "checkbox" && !inputList[i].checked)
checkedval = false;
}
inputList[0].checked = checkedval;
}

<asp:CheckBox ID="chkselect" runat="server" Enabled="False" TabIndex="8" onclick="CheckAll(this)" />
<asp:CheckBox ID="chkselect" runat="server" Enabled="False" TabIndex="8" onclick="CheckUnCheck(this)" />

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

Login to post response