javascript - Getting all selected checkboxes' corresponding values in an array -
please have @ following code:
$("#savebutton").click(function(){ $this = $("#tabledata").find("input:checked").parent().parent(); tea = $this.find(".teacls").text(); $.ajax({ type: "post", url: "chkselectedvalues.php", data: "tea=" + tea, success: function(msg){ $("#thefield").html(msg); } }); });
now if multiple checkboxes selected, tea
, flower
end concatenating text
s fields. if 2 checkboxes selected , 1 contains word some
, other 1 contains word text
, tea
variable gets value: sometext
. want tea
array containing these values (in case some
, text
) since need pass them in ajax request , want catch in chkselectedvalues.php
structure:
<table #tabledata> <tr> <td .teacls></td> <td> checkbox here</td> </tr> <tr> .....
how can this? in advance.
this should work:
var tea = $(':checked').map(function() { return this.value; }).get();
demo @ http://jsfiddle.net/alnitak/dwevr/
edit updated reflect op's clarification:
var tea = $(':checked').map(function() { return $(this).parent().siblings('.teacls').text(); }).get();
Comments
Post a Comment