如何在一个数组列表中获取所有选择框值 [英] How to fetch all select box value in one array list

查看:102
本文介绍了如何在一个数组列表中获取所有选择框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在jsp中生成了动态选择框,并给定了名称cb01,cb03..cb63等. 现在,我想在ArrayList或Map或数组中的Action类变量中获取这些选择框值. 请告诉我该怎么做.

I have generated dynamic select box in jsp and given names cb01,cb03..cb63 etc. Now i want to fetch these select box value in Action class variable like in ArrayList or in Map or in a array. Please tell me how to do it.

推荐答案

使用multiple="true"

<s:select name="mylist" id="id_mylist" list="countryList" multiple="true"/>

提交表单时调用以下Java脚本.这实际上将标记列表中的所有元素为选中状态.

On submit of the form calling the following Java Script. This will essentially mark all the element in the list as selected.

function doSubmit(){
 var mylistvar =document.getElementById("id_mylist");        
             if(mylistvar  !=null){      
                for(var x=0;x<mylistvar.options.length;x++){        
                    mylistvar.options[x].selected=true;
                }
             }

}

上面使用的ArrayList变量可能看起来像这样.

The ArrayList variable used above could looks like this.

private ArrayList<String> countryList = new ArrayList<String>();

这样,提交表单时,列表中的所有值将直接作为数组列表绑定到服务器.

This way when the form is submitted all the values in the list would be bind to the server directly as an arraylist.

这篇关于如何在一个数组列表中获取所有选择框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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