Reputation: 6341
In my project, I have a series of checkbox inputs. When users check/uncheck them, the I use $.get
in javascript to send the values to a different page.
What I mean is:
<form id="category_search">
<input name="category" type="checkbox" id="1" value="1"> <label for="1"> Cat1 </label>
<input name="category" type="checkbox" id="2" value="2"> <label for="2"> Cat2 </label>
<input name="category" type="checkbox" id="3" value="3"> <label for="3"> Cat3 </label>
...
</form>
When they are clicked, I use $("#category_search").serialize()
to get the checked values and send them to the different page.
But when they are sent, they are shown in the url as:
category=1&category=2&category=3
I would like to send them altogether (as an array?) like the following:
category=1,2,3
How can I achieve this?
Upvotes: 1
Views: 47
Reputation: 2165
replace your name="category"
to name="categories[]"
note: []
show that it's array
Upvotes: 2