I want to add a value to a checkboxlist using javascript /jquery.The code below is my sample code
function getExpertise() {
$.ajax({
type: "POST",
url: "Sample.asmx/GetExpertiseBySpecialization",
data: "{sId: '" + $('#<%=ddlSpecialization.ClientID%>').val() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response) {
var expertise = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
$('#<%=chkExpertise.ClientID%>').attr('disabled', false).removeOption(/./).addOption('-1', 'Please select expertise');
for (var i = 0; i < expertise.length; i++) {
var val = expertise[i].Id;
var text = expertise[i].Expertise;
$('#<%=chkExpertise.ClientID%>').addOption(val, text, false);
}
}
});
}
source :
http://forums.asp.net/p/1416683/3127300.aspx
A CheckBoxList (or RadioButtonList for that matter) renders as a tag with CheckBoxes and an HTML Label element in the tags. To add items you would need to add a and or to the table, which I definitely would not advise you to do with JavaScript, since they would not persist server-side and would disappear if a PostBack occurred. I’d suggest you do a PostBack and add the items server-side.