I have an issue which I hope someone can help me with. I’m able to retrieve the text value of my checkbox. What I want to achieve is every time I click on a checkbox, it adds the text to the input with an id of “Selected”. for example: if checkbox a, checkbox b, checkbox c are checked, I want to show “a, b, c”. Instead what I’m getting are the text of the current one that is checked. Any help would be great.
$(document).ready(function(){
$("#ListBox input").click(function() {
var cbText = $(this).next().text();
$('#Selected').val(cbText);
});
});
It sounds like you want
#Selectedto have the text values for the currently selected checkboxes.If that’s right, try this: http://jsfiddle.net/nAACW/4/ (updated)
EDIT: Changed to use
$('#ListBox').find(':checked')instead of$(this).parent().find(':checked')as correctly suggested by @Felix Kling