如何使用PHP获得多选项选择中的所有选项? [英] how can I get all options in a multi-options select using PHP?

查看:103
本文介绍了如何使用PHP获得多选项选择中的所有选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用2个选择菜单,其中一个具有值,另一个为空,并且当用户从左侧选择项目并单击Bitton时,所选项目将移至右侧菜单.此页面上有一个模拟程序示例 http: //jquerybyexample.blogspot.com/2012/05/how-to-move-items-between-listbox-using.html

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

唯一的问题是当我执行$ _POST ['lstBox2']时,我仅获得所选值.但是在这里,我想$ _POST是否选择所有选项天气.

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.

我已经完成了此jquery代码,但是如果使用过的人错误地单击了一个选项,则php将尝试仅发布一个

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');
});

有人可以告诉我php中是否有一种方法可以始终$ _POST他们所重视的一切?

can someone tell me if there a way in php to always $_POST all they value?

谢谢

推荐答案

只需将问题中的JavaScript代码移动到表单的submit回调中即可.

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);
});

这篇关于如何使用PHP获得多选项选择中的所有选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆