I have a list of checkboxes, like so:
<input type="checkbox" value="12" name="urssaf-check[]" class="urssaf-check">
<input type="checkbox" value="13" name="urssaf-check[]" class="urssaf-check">
I need to retrieve an array of the ids (values of the checkboxes) selected and pass it as a parameter in an url. So far I have this:
var items = [];
$('.urssaf-check').each(function (key, object) {
items.push($(this).val());
});
Which gives me:
["12", "27", "26", "15", "28", "29", "30", "16", "14", "19", "17", "18", "20", "31", "32", "33", "21", "22", "34", "23", "24", "25"]
So far so good, but now I need this in an url, so that when I do $_GET['ids'] or similar in the controller that will write the content of the page I can see that same array of numbers.
What I try now is this:
var array = { ids : items };
var params = $.param( array, true );
And params gives me:
ids=12&ids=27&ids=26&ids=15&ids=28......
Which in the var_dump of the get parameter will result on me only getting the id of the last item. If I manually add [] after "ids" it will work fine, but I want to know what is the proper way to do this with jQuery.
Edit: I need the url to open in a different window, I'm doing it like this:
function MM_openBrWindow(theURL,winName,features) {
window.open(theURL,winName,features);
}
MM_openBrWindow($(this).attr('data-url')+'/?'+params, 'name', "scrollbars=yes,width=1000,height=720");
jointo concate the array with special character in javascript and later useexplode()in your PHP code.$('form').serialize()to get what you want, but that would keep the elements name etc ?