To allow multiple selection the parameter name must be an array
<SELECT NAME="cats[]" id="cats" class="cats">
<OPTION value="1">1</OPTION>
<OPTION value="2">2</OPTION>
</SELECT>
Notice the array braces [] following the name parameter. Without them
the parameter can only hold one item at a time.
On the server side you'll need to process cats as an array:
$cats = array();
$cats = $_POST['cats'];
foreach($cats as $cat)
{
// do something with each cat here
}
Hope this helps
On Jan 4, 2:52 pm, ChrisMc <[email protected]> wrote:
> Hello,
>
> I have a form with multi select field like so:
>
> <SELECT NAME="cats" id="cats" class="cats">
> <OPTION value="1">1</OPTION>
> <OPTION value="2">2</OPTION>
> ...
> </SELECT>
>
> If I'm passing one value script works, but if I have multiple options,
> it only gets me last in array.
>
> jquery script working this out like:
> $(document).ready(function()
> {
> $("#cats").blur(function(){
> alert($(this).val()); //this shows ok (ex. "1,2,3")
>
> $.post("user_availability.php",{ cats: $(this).val
> () } ,function(data)
> {
> alert(data); // this returns only ex. "3"
> });
> ...
>
> user_availability.php only takes passed data echo's for the sake of
> simplicity in this case. and the echo is the same as in alert(data)-
> that is "3".
>
> Help me please. I'm new to jquery and I need to maintain the same
> structure as shown as I have already done this form for 7 more fields,
> so a lot of work put in.