I am writing a jQuery function on the click event of a checkbox list, which stores the value in a string when one item is checked and it removes the string when it is unchecked. I am taking the closed label text and insert and remove it from the string. I can add the strings but I am not able to remove it.
Here is my code:
var currentage = '';
$('#<%=chk_ange.ClientID%> input:checkbox').click(function () {
var str = $(this).next('label').text();
if ($(this).is(':checked')) {
if (currentage.indexOf($(this).next('label').text()) == -1) {
currentage = currentage + str;
}
alert('checked' + currentage);
}
else {
currentage.replace(str, "Hello");
//currentage.replace(str, 'None');
alert('unchecked' + currentage);
}
}
I am storing the values in a global variable so that i can compare the value in each click.