English 中文(简体)
使用JQuery将ListBox选定的值作为隐藏字段发送
原标题:Sending ListBox selected values as Hidden Field using JQuery

I want to be able to send all the selected values from a listbox as a hidden field using JQuery. I was able to send/retrieve a single value on form submission.

如果有人可以分享一些代码片段,那将有所帮助。

提前感谢!

最佳回答

嗯,你到底在要求什么还不太清楚。HTML中没有“多选下拉列表”。要进行多选,您需要指定

<select id="foobar" multiple>

这将创建一个列表框,您可以在其中选择多个元素。使命感

var sel = $( #foobar ).val();

将返回所选项目的数组

编辑

要从每个选项中获取文本,请使用.map()jQuery.map(()。示例:

var sel = $( #foobar ).children( option:selected ).map(function(i,e){
    return e.innerText;
}).get();

这将创建一个数组,其中包含所有选定条目的文本。

问题回答

绝对没有必要这样做。 您显然使用request.getPara公尺(。 而不是request.getParacales(>,并想知道为什么只归还第一种价值。

只需相应地修复servlet代码:

String[] selectedItems = request.getParameterValues("dropdownname");

不需要丑陋的JS/jQuery黑客将它们全部作为单个参数发送。在未来的问题中,试着问如何解决问题,而不是如何实现一个解决方案,毕竟这个解决方案本身可能不是正确的解决方案。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签