<body>
<form id="form1" name="form1" method="post" >
<table>
<select name="allPur" style="width:300" size="30" multiple>
<%
for (int i = 0; i < sorts.size(); i++) {
BalkSubSort su = (BalkSubSort)sorts.get(i);
if (sub.getName() != null) {
%>
<option value="<%=sub.getId()%>"><%=sub.getName()%>
<%
}
}
%>
</optgroup>
</select>
</td>
</tr>
<tr>
<td class="td2" colspan="3" align="center"><input type='button'
class='button1' class="button1" value="提 交" onclick="doSubmit()">
</table>
</form>
</body>
如果把select的值传到后台servlet接收:
String[] allPur = (String[])request.getParameterValues("allPur");
js:
function doSubmit(){
//最重要的是先选中才能提前否则allPur = null;
***selectedAll(document.form1.allPur);***
document.form1.action = "XXXXX";
document.form1.submit();
}
function selectedAll(select){
var ops = select.options;
for(var i=0;i<ops.length;i++){
ops[i].selected = true;
}
}
为什么request.getParameterValues(“XXX”)接收select数组的值为null?因为提交的时候没有让select全部选中。