jquery - cant get values to keep adding to input -
i have issue hope can me with. i'm able retrieve text value of checkbox. want achieve every time click on checkbox, adds text input id of "selected". example: if checkbox a, checkbox b, checkbox c checked, want show "a, b, c". instead i'm getting text of current 1 checked. great.
$(document).ready(function(){ $("#listbox input").click(function() { var cbtext = $(this).next().text(); $('#selected').val(cbtext); }); });
it sounds want #selected
have text values selected checkboxes.
if that's right, try this: http://jsfiddle.net/naacw/4/ (updated)
$(document).ready(function(){ $("#listbox input").click(function() { var cbtext = $('#listbox').find(':checked').next() .map(function() { return $.text([this]); }).get().join(', '); $('#selected').val(cbtext); }); });
edit: changed use $('#listbox').find(':checked')
instead of $(this).parent().find(':checked')
correctly suggested @felix kling
Comments
Post a Comment