问题
I am using 2 select menus where one have value and the other one is empty and when a user select items from the left and click a bitton the selected items are moved to the right menu. a similler example is on this page http://jquerybyexample.blogspot.com/2012/05/how-to-move-items-between-listbox-using.html
the only problem is when i do a $_POST['lstBox2 '] I only get the selected value. But in here I want to $_POST all option weather they are selected or not.
I have done this jquery code that does that but if a used clicked on one option by mistake then php will try to post only one
$("#lstBox2 option").each(function() {
$(this).attr('selected', 'selected');
});
can someone tell me if there a way in php to always $_POST all they value?
thanks
回答1:
Just move the JavaScript code in your question to the submit
callback of your form.
$("form:has(#lstBox2)").on('submit', function () {
$("#lstBox2 option").prop('selected', true);
});
回答2:
You can send the information of selected options in JSON format, and in server-side, you can easily use PHP json_decode() to parse the information.
来源:https://stackoverflow.com/questions/15752924/how-can-i-get-all-options-in-a-multi-options-select-using-php