I am using asp.net 4.0
I have a checklistbox and a checkbox. I have to select all checkbox on of checklisbox on checking the checkbox.I am writing the following code.
function Select(CheckBox, ChecklistBoxID) {
var TargetBaseControl = document.getElementById('<%= chkAction.ClientID%>');
var Inputs = TargetBaseControl.getElementsByTagName("input");
for (var n = 0; n < Inputs.length; ++n)
Inputs[n].checked = CheckBox.checked;
}
My query is, in the above function, I am passing second parameter for checklistbox, How to pass this id in below line of code.
var TargetBaseControl = document.getElementById('<%= chkAction.ClientID%>');
EDIT
I have two more checklistbox, So i don;t want to hardcode the controlID. I was thinking of passing the ID as parameter. thus the code will become reusable…
<asp:CheckBox ID="chkact" onclick="javascript:Select(this, 'chkAction');" ClientIDMode="Static" runat="server" Text="Select All" />
Below was the fix.
The checklboxlist need to initialize a property ClientIDMode = “Static”. Finally i could ascertain the ID using below code.