1

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?

1 Answer 1

2

replace your name="category" to name="categories[]" note: [] show that it's array

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the suggestion. I changed the name attribute from category to categories[]. Now the params are shown in the url as `categories[]=1&categories[]=2. It did not do the job.
in this case you will have proper array, does it matter how it looks if you send it via $.get? if yes you could format it as you want with js.
Hmm.. you are right. I do have a proper array when I try your method. Thank you.

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.