1

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.

1
  • Look at what you did, you said array and you have an object. Commented Aug 23, 2012 at 12:14

2 Answers 2

1
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(","));
Sign up to request clarification or add additional context in comments.

3 Comments

second one is my solution. How can I use in this function view.setColumns([0,1,2,3, 4]); 1,2,3,4 is my chexboxes values.
myValues is an array in the end, so you can just pass it: view.setColumns(myValues);
I write view.setColumns(myValues); It does not work. But I define an array like this var array=[1,2,3,4] and Use it like this : view.setColumns(array); It works well. What is the difference between them. Please help. Thanks.
1

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();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.