当前位置: 代码迷 >> Java Web开发 >> 请问select下拉框有关问题
  详细解决方案

请问select下拉框有关问题

热度:94   发布时间:2016-04-16 21:25:40.0
请教select下拉框问题
下载了的二级联动源码,想把它移植到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该怎么修改?谢谢!!
------解决思路----------------------
换成document.getElementById('categoryId')
  相关解决方案