newbreedcc
asked on
Hotmail Style - "Select All" checkbox on a asp:checkbox - need little help
Hi,
I have OnClick script running off my asp:checkbox "Select All" that call a javascript function in order to check and uncheck all checkboxes... I got that part working fine,
Now, once I have selected all checkboxes and then uncheck one checkbox further down I want my "Select All" checkbox at the top to be unchecked... That's part I cant seem to get working.
Here's my javascript so far and also my OnClick event from my asp:checkbox. Hope to hear from you guys soon, thanks
function select_deselectAll (chkVal, idVal) {
var frm = document.forms[0];
// Loop through all elements
for (i=0; i<frm.length; i++) {
// Look for our Header Template's Checkbox
if (idVal.indexOf ('chxSelectAll') != -1) {
// Check if main checkbox is checked, then select or deselect datagrid checkboxes
if(chkVal == true) {
frm.elements[i].checked = true;
}
else {
frm.elements[i].checked = false;
}
}
// Work here with the Item Template's multiple checkboxes
else if (idVal.indexOf ('chxSelect') != -1) {
// Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
if(frm.elements[i].checked == false) {
//frm.elements[1].checked = false; //Uncheck main select all checkbox
//frm.getElementById('chxS electAll') .checked = false;
alert("uncheck master box");
var myId = document.getElementById("c hxSelectAl l");
alert(myId);
//myId.checked = false;
}
}
}
}
<asp:TemplateColumn HeaderText="Workflow">
<HeaderTemplate>
<asp:CheckBox id="chxSelectAll" OnClick="javascript: return select_deselectAll(this.ch ecked, this.id);" Text="All" Runat="server" Width="50px"></asp:CheckBo x>
</HeaderTemplate>
<ItemTemplate>
<asp:checkbox id="chxSelect" OnClick="javascript: return select_deselectAll(this.ch ecked, this.id);" Runat="server" Width="50px" Visible=False></asp:checkb ox>
</ItemTemplate>
</asp:TemplateColumn>
The bug lies within the last part of my javascript function.
I have OnClick script running off my asp:checkbox "Select All" that call a javascript function in order to check and uncheck all checkboxes... I got that part working fine,
Now, once I have selected all checkboxes and then uncheck one checkbox further down I want my "Select All" checkbox at the top to be unchecked... That's part I cant seem to get working.
Here's my javascript so far and also my OnClick event from my asp:checkbox. Hope to hear from you guys soon, thanks
function select_deselectAll (chkVal, idVal) {
var frm = document.forms[0];
// Loop through all elements
for (i=0; i<frm.length; i++) {
// Look for our Header Template's Checkbox
if (idVal.indexOf ('chxSelectAll') != -1) {
// Check if main checkbox is checked, then select or deselect datagrid checkboxes
if(chkVal == true) {
frm.elements[i].checked = true;
}
else {
frm.elements[i].checked = false;
}
}
// Work here with the Item Template's multiple checkboxes
else if (idVal.indexOf ('chxSelect') != -1) {
// Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
if(frm.elements[i].checked
//frm.elements[1].checked = false; //Uncheck main select all checkbox
//frm.getElementById('chxS
alert("uncheck master box");
var myId = document.getElementById("c
alert(myId);
//myId.checked = false;
}
}
}
}
<asp:TemplateColumn HeaderText="Workflow">
<HeaderTemplate>
<asp:CheckBox id="chxSelectAll" OnClick="javascript: return select_deselectAll(this.ch
</HeaderTemplate>
<ItemTemplate>
<asp:checkbox id="chxSelect" OnClick="javascript: return select_deselectAll(this.ch
</ItemTemplate>
</asp:TemplateColumn>
The bug lies within the last part of my javascript function.
> var myId = document.getElementById("c hxSelectAl l");
if you view source, does it actually get that id?
using controls in web forms might mess up your naming.
you should look into control.clientid.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebUIControlClassClientIDTopic.asp
"ASP.NET automatically generates a ClientID for a server control regardless of whether you have specified an ID property for it or not. This property is used to identify a control for client-side operations, such as ECMAScript functions."
if you view source, does it actually get that id?
using controls in web forms might mess up your naming.
you should look into control.clientid.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebUIControlClassClientIDTopic.asp
"ASP.NET automatically generates a ClientID for a server control regardless of whether you have specified an ID property for it or not. This property is used to identify a control for client-side operations, such as ECMAScript functions."
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ClientSideScript.asp
and i forgot the link :)
and i forgot the link :)
ASKER
Hi,
Thank you for the aricle, helped alot.
Thank you for the aricle, helped alot.
look here : http://forums.devshed.com/archive/t-11535
Regards!
B..M