-2
我有一個jsp,有兩個下拉位置和部門。無法從servlet訪問JSP下拉值
根據通過Ajax的位置值填充部門下拉列表的值。
但是當我嘗試保存頁面時,如果選擇了部門中的第一項下拉菜單,我無法訪問部門下拉列表的值。
但是如果選擇第二或第三項,則可以從servlet訪問它。
<form id="form1" name="crtdocfrm" action="CreateLocation" method="post">
<fieldset width="50%">
<legend>Division</legend>
<table id="table1">
<tr class="tr_stylebutton">
<td>Location Name</td>
<td><select name="locName" onChange="showDept(this.value)">
<option value="-1">--select--</option>
<%
Iterator itrLocation = arlLocation.iterator();
while (itrLocation.hasNext()) {
%>
<option value=<%=itrLocation.next()%>><%=itrLocation.next()%>
</option>
<%}%>
</select></td>
</tr>
<tr class="tr_stylebutton">
<td>Department Name</td>
<td>
<select name="ddDeptName" onChange="alert(this.value)"></select>
</td>
</tr>
<tr class="tr_stylebutton">
<td>Division ID</td>
<%
LocationPolulate lp = new LocationPolulate();
int Div_Id = lp.DivisionId();
%>
<td><input type="text" name="divID" disabled="true" value=<%=Div_Id + 1%>/></td>
</tr>
<tr class="tr_stylebutton">
<td>Division Name</td>
<td><input type="text" name="divName" value=""/></td>
</tr>
</table>
<table border="0" width="55%" align="left" id="table-button">
<tr class="tr_stylebutton">
<td align="right"><input type="submit" value="Save" class="button"/></td>
<td align="left"><input type="submit" value="Cancel" class="button"/></td>
</tr>
</table>
</fieldset>
<br/>
</form>
的Servlet
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
int intLocId = Integer.parseInt(request.getParameter("locName"));
String strDivNm = (String) request.getParameter("divName");
int intDeptId = Integer.parseInt(request.getParameter("ddDeptName"));
LocationPolulate lp = new LocationPolulate();
int Res = lp.InsertDivision(strDivNm, intLocId, intDeptId);
if (Res == 0) {
request.setAttribute("Errmsg", "Error Cannot Save Division");
RequestDispatcher dis1 = getServletContext().getRequestDispatcher("/AddDivision");
dis1.forward(request, response);
} else {
int Div = lp.DivisionId();
request.setAttribute("succmsg", "Successfully saved Division with division id:" + Div);
RequestDispatcher dis1 = getServletContext().getRequestDispatcher("AddDivision.jsp");
dis1.forward(request, response);
}
}
任何想法?
功能stateChanged() { 如果(xmlHttp.readyState == 4 || xmlHttp.readyState == 「完成」) { 變種showdata = xmlHttp.responseText; var strar = showdata.split(「:」); \t if(strar.length == 1) \t {document.getElementById(「locName」)。focus(); \t提醒(「請選擇位置ID」); \t \t} \t else if(strar.length> 1) \t {option = new Option(「--- Select ---」,-1); document.crtdocfrm.ddDeptName.options [0] = option; (var i = 0; i
Alivia
2011-12-16 11:55:08