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

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

问题描述

我在 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.

推荐答案

在 JSP 中使用 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天全站免登陆