I have two html drop down list, their value are retrieved from the database by using jsp.
<%
String query =" SELECT question_text,question_id FROM questions WHERE id = ?";
PreparedStatement stmt = conn.prepareStatement(query);
stmt.setString(1,request.getParameter("QID"));
ResultSet rs = stmt.executeQuery();
if(!rs.next()) {} else {%>
<form action="#" method="post">
<p> First Question </p>
<select name="currentQuestion">
<%do{%>
<option value="<%=rs.getString("question_id")%>"><%=rs.getString("question_text")%> </option>
<%}while(rs.next());}%>
</select>
<%
String query =" SELECT question_text,question_id FROM questions WHERE id = ? AND question id != ? ";
PreparedStatement stmt = conn.prepareStatement(query);
stmt.setString(1,request.getParameter("QID"));
stmt.setString(2,CHOOSEN QUESTION);
ResultSet rs = stmt.executeQuery();
if(!rs.next()) {} else {%>
<p> Next Question </p>
<select name="currentQuestion">
<%do{%>
<option value="<%=rs.getString("question_id")%>"><%=rs.getString("question_text")%></option>
<%}while(rs.next());}%>
</select>
</form>
Now, I what when the user choose a specific question from the first drop down list, the value of the second drop down list does not include that question ?
is anyone know how to do that ?
CHOOSEN QUESTIONanywhere in the code.idandnametags in theoptionelement.CHOOSEN QUESTIONis an illegal name for a variable since it contains a space.onChangeof the first dropbox (before the user chooses an option – you’ll probably want to have the second dropbox disabled)formwhich will eventually submit the user’s choices to a JSP (server-side).UPDATE (example code for changing options using JS):