how can I get all options in a multi-options select using PHP?

ⅰ亾dé卋堺 提交于 2019-12-12 02:19:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!