I have dropdown lists in two forms in a single .jsp. I would like the change of any of the lists to trigger a post back to the .jsp itself with the currently selected parameters in both forms. But I couldn't get it work. Here is the relevant part of the code:
Both forms are in the SearchBrowse.jsp. This is form1 (form2 will have an identical structure. Note that, I tried to use the same form id and hope to achieve this effect but didn't work):
<c:set var="counter1" value="0"></c:set>
<c:set var="curSp" value="0"></c:set>
<form id="myForm" method="post" action="SearchBrowse.jsp">
<b>Select Species:</b>
<select name="spChoice" size="1" onchange="submit()">
<c:forEach var="sp" items="${species}">
<c:choose>
<c:when test="${param.spChoice == sp.name}">
<c:set var="spFlag" value=" selected"></c:set>
<c:set var="curSp" value="${counter1}"></c:set>
</c:when>
<c:otherwise>
<c:set var="spFlag" value=""></c:set>
</c:otherwise>
</c:choose>
<option value="<c:out value='${sp.name}' />" <c:out value='${spFlag}' />>
<c:out value="${sp.name}"></c:out>
</option>
<c:set var="counter1" value="${counter1 +1}"></c:set>
</c:forEach>
</select>
<br></br>
</form>
This is form2:
<c:set var="counter2" value="0"></c:set>
<c:set var="curChrm" value="0"></c:set>
<%-- Implement a dropdown list and and determine which javabean list to be displayed in the table --%>
<form id="myForm" method="post" action="SearchBrowse.jsp">
<b>Select Chromosome to browse summary:</b>
<select name="chrmChoice" size="1" onchange="submit()">
<c:forEach var="chrms" items="${riceChrmLocation}">
<c:choose>
<c:when test="${param.chrmChoice == chrms.name}">
<c:set var="selectFlag" value=" selected"></c:set>
<c:set var="curChrm" value="${counter2}"></c:set>
</c:when>
<c:otherwise>
<c:set var="selectFlag" value=""></c:set>
</c:otherwise>
</c:choose>
<option value="<c:out value='${chrms.name}' />" <c:out value='${selectFlag}' />>
<c:out value="${chrms.name}"></c:out>
</option>
<c:set var="counter2" value="${counter2 +1}"></c:set>
</c:forEach>
</select>
<br></br>
</form>
Currently when one form changed, the selection parameter of the other dropdown list is not posted back. I am not sure if it is the problem with scope. I tried various ways but couldn't get it right. Did I do something wrong here? Also is this code a bit messy? (If it is, do u have any better suggestion on coding it in a neat way?) Thanks a lot.