Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select2 multi-value only sending one value in POST

Here is a snippet of my code: http://jsfiddle.net/natatkinson/xbWEb/

Javascript:

$(document).ready(function () {     $("#tags").select2({         maximumSelectionSize: 3     });  }); 

HTML:

<form name="form1" id="form1" action="" method="GET"> <fieldset>     <legend>Shoe Info</legend>     <dl>    <dt>Name:</dt>          <dd>             <input type="text" name="name" id="name" size="40" placeholder="Shoe name" required autofocus>         </dd>     </dl>   <dt>Tags:</dt>      <dd>         <select multiple="" name="tags" id="tags" style="width:100%;">             <option value="0">Select Tags</option>             <option value="2">racing flat</option>             <option value="3">track spikes</option>             <option value="1">trainer</option>         </select>     </dd>     </dl> </fieldset> <p class="submit-buttons">     <input type="submit" class="button1" name="submit" id="submit" value="Add Shoes" /> </p> 

All that submits is 1 value, not a comma separated list like the documentation says.

like image 685
Nate Atkinson Avatar asked Oct 18 '13 20:10

Nate Atkinson


People also ask

How do I set Select2 values?

To set selected value of jQuery Select2 with JavaScript, we call val and then trigger . Then we set its value with val to the option with value 0. Finally, we call trigger with 'change' to update the drop down to show the value we set.

How do you add select all in Select2?

Add Select All Option to jQuery Select2:First create the markup for the multi-value select box and a check box for selecting all option. Now add this java script to the page. The above script will be executed by onclick() event of the check box.

How do you delete Select2 data?

In order to clear the selection of those values which are selected using a Select2 drop down,we can use the empty() function. The dropdown can be reset using Jquery. $("#select2_example"). empty();


1 Answers

You must use [] for multiple value contained form control's name. Correct using at bottom:

<select multiple="" name="tags[]" id="tags" style="width:100%;"> 
like image 111
Ahmet Erkan ÇELİK Avatar answered Sep 18 '22 15:09

Ahmet Erkan ÇELİK