请教select下拉框问题

abcxiaoye 2015-01-25 11:44:37
下载了的二级联动源码,想把它移植到strtut标签网页中来,相关代码如下:
<html:form  action="baseData/med.do"  method="post"  focus="title" enctype="multipart/form-data" onsubmit="return 
save();">
<input type="hidden" name="command" value="add" />
<html:hidden property="id"/>

<tr>
<td align="right">类别:</td>
<td align="left">
<select id="directoryId" name="directoryId" onchange="change()">
<option value="0" selected="selected">
请选择主目录
</option>

<logic:iterate id="blist" name="dcs" scope="request">
<option value="${blist.id}">
${blist.name}
</option>
</logic:iterate>

</select>
<select name="categoryId" id="categoryId">
<option value=""><font color="#FF0000">--选择子目录--</font></option>
</select>

<td colspan="2" align="center"><html:submit><bean:message key="button.submit" /></html:submit></td>
</tr>
</table>
</html:form>



<script type="text/javascript">
var req;

function init() {
if(window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
}
function change() {
init();
var url = "getChilds.jsp?id="+ escape(document.getElementById('directoryId').value);
req.open("GET", url, true);
req.onreadystatechange = callback;
req.send(null);
}
</script>

getChilds.jsp页面
<%
String id = request.getParameter("id");

CategoryDao dao = new CategoryDao();
List cs = dao.findByHQL("from Category where directoryId="+ Integer.parseInt(id));

System.out.println(cs.size());
StringBuffer buf = new StringBuffer();
buf.append("document.medForm.categoryId.length = " + (cs.size()+1) + ";\n");//这里document.medForm.categoryId不知怎么修改,请高手出招
buf.append("document.medForm.categoryId.options[0].value = '';\n");
buf.append("document.medForm.categoryId.options[0].text = '--请选择--';\n");
buf.append("document.medForm.categoryId.selectedIndex = 0;\n");

int i=0;
for(Iterator iter = cs.iterator(); iter.hasNext(); i++) {
Category t = (Category)iter.next();

buf.append("document.medForm.categoryId.options[" + (i+1) + "].value = '" + t.getId() + "';\n");
buf.append("document.medForm.categoryId.options[" + (i+1) + "].text = '" + t.getName() + "';\n");
}

原来的代码form是有名称的
<form name="medForm" id="medForm">
现在的html:form没有medForm了,
getChilds.jsp页面一系列的document.medForm.categoryId该怎么修改?谢谢!!
...全文
109 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
yschat2012 2015-01-25
  • 打赏
  • 举报
回复
换成document.getElementById('categoryId')

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧