Check all checkboxes with javascript

manared

Well-known member
Joined
Jun 1, 2006
Messages
84
Programming Experience
1-3
I am using vb.net 2005 with asp.net. I have a web page with some checkboxes on it. There is also a gridview with a checkbox column. I found some javascript that checks all checkboxes when one certain checkbox on the gridview is selected. The problem is that it checks ALL the checkboxes on the entire page. I want it to only select the ones that are in the gridview. Is this possible at all? Here is the javascript that I have now. Again, it works, but it selects every one on the page instead of only the gridview checkboxes.

HTML:
function SelectAllCheckboxes(spanChk){
// Added as ASPX uses SPAN for checkbox
var oItem = spanChk.children;
var theBox=(spanChk.type=="checkbox")?spanChk:spanChk.children.item[0];
xState=theBox.checked;
elm=theBox.form.elements;
for(i=0;i<elm.length;i++)
if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
{
//elm[i].click();
if(elm[i].checked!=xState)
elm[i].click();
//elm[i].checked=xState;
}
}
 
Maybe you can use ASP and just turn the Postbock property to true for the check all checkbox. The page will have to reload but then you can do the code yourself programmatically. I know this may not be the route you want to take but it's the best I can think of for now; of course I am a newbie to ASP.NET
 
Back
Top