Click here to Skip to main content
15,896,489 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using javascript for one of the ascx controls in my application.

The ascx controls have checkbox lists inside a panel. I have a javascript function to handle the onclick of checkboxlist items.

I am trying to get the checkbox list as

var checkBoxList = document.getElementById("<%= CheckBoxList1.ClientID %>");

--> it gives checkbox list as null; Also trying with,

var checkBoxList = document.getElementById("CheckBoxList1");

hen also the value is null.

How can I get the checkboxlist item here?
Posted

hi,

try to register your javascript function at runtime using scriptmanager.
 
Share this answer
 
If you can use jQuery you can try selecting the checkboxlist using the jQuery Selector. It will be easier and can be altered as much.

$("#{runtime id of the element")

To get started you may refer this

http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery[^]

And for jQuery selectors, you may refer this

http://api.jquery.com/category/selectors/[^]

If you dont want to go with jQuery please provide info on what client side event you are trying to get the checkbox list. Is that within the onclick event?
 
Share this answer
 
A checkbox list is a composite control. It is rendered as individual checkboxes in the client side. You will have to read each checkbox with its id or class to get the selected values.

View the source of the page and you will understand how a checkbox list is rendered on client side.

complete solution in javascript here ...

http://hspinfo.wordpress.com/2008/08/14/get-checkboxlist-values-using-javascript/[^]
 
Share this answer
 
Make sure you are putting this code in aspx page. ClientID will not work in external js file.
For external js file, try following in jQuery:

$("[id*=CheckBoxList1] input:checkbox").prop('checked', true);

For more information to get/set checkboxlist items in jquery, check following:

ASP.NET CheckBoxList Operations with jQuery[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900