Reputation: 15866
Html
<td>
<input type="checkbox" value="1" id="t1" checked="checked" class="filter" /><label
for="t1">T1</label>
</td>
<td>
<input type="checkbox" value="2" id="t2" checked="checked" class="filter" /><label
for="t2">T2</label>
</td>
<td>
<input type="checkbox" value="3" id="t3" checked="checked" class="filter" /><label
for="t3">T3</label>
</td>
<td>
<input type="checkbox" value="4" id="t4" checked="checked" class="filter" /><label
for="t4">Toplam</label>
</td>
Script:
$(document).ready(function () {
$(".filter").click(function () {
drawChart();
});
});
function drawChart()
{
// I want to get checkboxes value here.
var filters = {$("#t1").val(),$("#t2").val(),$("#t3").val(),$("#t4").val()};
var view = new google.visualization.DataView(new google.visualization.DataTable(evalledData, 0.5));
view.setColumns([0, 4]); //here you set the columns you want to display
}
I want to get checkboxes value like above but I dont know correct syntax? Or I would pass array to drawChart. Could you write correct syntax to create an array of checkboxes values?
Edit
I want to set view columns with view.setColumns([0, 4]);
with using checkboxes. I mean I want to use view.setColumns([array]);
instead of view.setColumns([0, 4]);
Thanks.
Upvotes: 1
Views: 351
Reputation: 700322
I assume that by value, you actually mean whether the checkbox is checked or not. (A checkbox always has the same value, regardless of whether it's checked or not.)
To get an array of boolean values:
var filters = $('.filter').map(function(i, e){
return $(e).is(':checked');
}).get();
Upvotes: 1
Reputation: 342635
var myValues = $(".filter").map(function () {
return this.value;
}).get();
console.log(myValues.join(","));
If you want only the checked ones:
var myValues = $(".filter:checked").map(function () {
return this.value;
}).get();
console.log(myValues.join(","));
Upvotes: 1