Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to post all values in a multiselect list and not just the selected ones?

I have two MultiSelect lists (AllProductList and SelectedProductList), AllProductList contains all products for a particular category and I add/clone options from the AllProductList to the SelectedProductList using JQuery.

I obviously only wish to post the values in the SelectedProductList and irrespective of whether they are selected or not.

I have wrapped the form tags around the SelectedProductList only and now need some way to post all option values in it, irrespective whether selected or not.

like image 443
LaserBeak Avatar asked Jan 25 '12 04:01

LaserBeak


People also ask

How do I create a drop-down list in Word that allows multiple selections?

Under Insert controls, click Multiple-Selection List Box. If you cleared the Automatically create data source check box in step 3, select a repeating field in the Multiple-Selection List Box Binding dialog box to which you want to bind the multiple-selection list box.


1 Answers

you could write some javascript that fills a hidden form element with all the values from the select, something like below, and on the serverside just use explode(",",$_POST["allValues"]) to get all options

<script>
var hiddenValues = "";
$(document).ready(function(){
   $("#mySelect option").each(function(){
       hiddenValues = $(this).val() + ",";
   })//end each

   $("#myForm").append("<input type='hidden' name='allValues' value='"+hiddenValues+"'>")
})
</script>

obviously, the above has a dependency on jQuery and your form has a id of myForm and that your multiselect has a id of mySelect :)

EDIT :
NOTE1 : that this saves only the values of the options, and not the labels from the select (a similiar method can be employed to save those as well). just keep this in mind

NOTE2 : beware if the values contain any commas, as this will invalidate your input (if not escaped in a way, or if not using some other delimiter)

like image 59
Bogdan Avatar answered Nov 12 '22 14:11

Bogdan