-2
私は2つのドロップダウンロケーションと部門を持つJSPを持っています。サーブレットからJSPドロップダウン値にアクセスできない
部門のドロップダウンの値は、Ajaxによるロケーションの値に基づいて設定されます。
しかし、ページを保存しようとすると、部門の最初の項目をドロップダウンした場合、部門のドロップダウンの値にアクセスできません。
しかし、2番目または3番目の項目が選択されている場合は、サーブレットからアクセスできます。
<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>
サーブレット
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関数(){ は、IF(xmlHttp.readyState == 4 || xmlHttp.readyState == "完全") {VAR showdata = xmlHttp.responseText。 var strar = showdata.split( ":"); \t if(strar.length == 1) \t {document.getElementById( "locName")。focus(); \tアラート( "Please Select Location Id"); \t \t \t else if(strar.length> 1) \t {option = new Option( "--- Select ---"、-1); document.crtdocfrm.ddDeptName.options [0] = option; (strar [i + 1]、strar [i]); for(var i = 0; i
Alivia
だけで不思議、あなたはあなたのコードが読める見つけるのですか? – BalusC
optionタグIteratorで、 '.next()'メソッドを各オプションに対して2回、valueとdisplayの値のために1回ずつ呼び出すことに気づいていますか? –