简体   繁体   English

在表单提交时发送多选选择的值

[英]Send a multi-select select's values on form submit

In a form I have 2 <select multiple> elements. 在形式上,我有2个<select multiple>元素。 First one is filled with <option> itens in server-side. 第一个在服务器端用<option> itens填充。

I have then developed a JavaScript code to move itens from one to another. 然后,我开发了JavaScript代码以将itens从一个移到另一个。 That's a basic multiselect feature. 这是基本的多选功能。

Now I must send second select's values back to server when form is submitted. 现在,提交表单后,我必须将第二个select的值发送回服务器。 But it only sends itens that are selected. 但是它仅发送选定的itens。 That's not the behavior I need, I want all existing itens to be sent. 那不是我需要的行为,我希望所有现有的iten都被发送。 Any idea how to implement it, preferably without using Ajax? 任何想法如何实现它,最好不使用Ajax?

I ended up not implementing it. 我最终没有实现它。 But if I would I'd just try to get all select's values into an array, JSON marshal them and put the string into the input hidden. 但是,如果我想尝试将所有select的值放入数组中,则JSON将它们编组,并将字符串隐藏在输入中。 I'd try to do it in form's submit event. 我会尝试在表单的Submit事件中进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM