开发者

Submit Form & Separate Checkbox Values with Commas

开发者 https://www.devze.com 2023-03-28 18:37 出处:网络
<form ... method=\"get\"> <checkbox name=\"category[]\" value=\"1\"> <checkbox name=\"category[]\" value=\"2\">
 <form ... method="get">
 <checkbox name="category[]" value="1">
 <checkbox name="category[]" value="2">
 <checkbox name="category[]" value="3">
 ...

I w开发者_运维问答ant the final get query to look like the following, if all items are checked: ?category=1,2,3

If only 1 and 3 are checked: ?category=1,3

What's the best way to achieve this?


You could use Javascript to manipulate a hidden field:

<input type="hidden" name="category" value="" />

When either checkbox is changed, update the value (i.e. "1,3" or "1,2,3") as needed.

0

精彩评论

暂无评论...
验证码 换一张
取 消