JSP页面表单联动,最新~~~

在接受到action的请求后,在后台首先查出连个集合,比如 所有的部门,所有的人员

List<UserInfoVO> users = userInfoFacede.getAllUsers();
request.setAttribute("users", users); //把值传给表单


List<DeptVO> dept = userInfoFacede.getAllDeptName();
request.setAttribute("dept", dept);





在jsp页面



var onecount;
onecount=0;
subcat=new Array();

<logic:iterate id="small" name="users" indexId="index">
subcat[${index}] = new Array("${small.username}","${small.deptid}","${small.userid}");
</logic:iterate>
onecount=${index+1};

function changelocation(locationid){
document.forms[0].areaid.options[0]=new Option("-请选择-","");
document.forms[0].areaid.length = 1;

var locationid=locationid;
var i;
for (i=0;i < onecount; i++) {
if (subcat[i][1] == locationid)
{
document.forms[0].areaid.options[document.forms[0].areaid.length] = new Option(subcat[i][0], subcat[i][2]);
//取到用户的ID和姓名 分别和数组对应
}
}

}



分别与之对应

<td align="right" bgcolor="#eeeeee">
所属部门:
</td>
<td>
<select name="rootid" id="rootid"
οnchange="changelocation(document.forms[0].rootid.options[document.forms[0].rootid.selectedIndex].value)">
<option value="" selected>
--请选择--
</option>
<logic:iterate id="big" name="dept">
<option value="${big.pid }">
${big.deptname }
</option>
</logic:iterate>
</select>
</td>


<td width="15%" align="right" bgcolor="#eeeeee">
任务负责人:
</td>
<td width="30%">
<select name="areaid" id="areaid">
<option value="" selected>
--请选择--
</option>
</select>
</td>


这样就可以实现选择任意一个部门就可以得到部门的所有成员了~~~~~~~~~
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章