I created JSP page containing form with two comboboxes, I need to pass the selected value from the first combobox to SQL statement used by the second combobox. Any suggestions?
<form name="subfrm" align="center" action="SaveSubscription">
Event Category: <select name="evnt_cat"> get the selected value
<option value="0">--Select Category--</option>
<%
try {
connect = DriverManager.getConnection("jdbc:odbc:MyEvent","","");
sql = "SELECT * FROM Event";
pstmnt = connect.prepareStatement(sql);
rs = pstmnt.executeQuery();
while(rs.next()) {
cat_e = rs.getString("Event_Category");
%>
<option value="<%=cat_e%>"><%=cat_e%></option>
<% }
rs.close();
pstmnt.close();
connect.close();
}
catch( Exception e ) {
System.out.println(e);
}
%>
</select><br/><br/>
Event Sub_Category: <select name="evnt_subcat">
<option value="0">--Select Subcategory--</option>
<%
try {
connect = DriverManager.getConnection("jdbc:odbc:MyEvent","","");
sql1 = "SELECT EventDetails.Event_Title FROM Event INNER JOIN EventDetails ON Event.Event_ID = EventDetails.Event_ID WHERE Event.Event_Category = ?";
pstmnt = connect.prepareStatement(sql1);
pstmnt.setString(1, "put the selected value from the first combobox"); rs = pstmnt.executeQuery();
while(rs.next()) {
cc = rs.getString("Event_Title");
%>
<option value="<%=cc%>"><%=cc%></option>
<% }
rs.close();
pstmnt.close();
connect.close();
}
catch( Exception e ) {
System.out.println(e);
}
%>
</select><br/><br/>
<input name="subusr" value="Subscribe" type="submit" align="center"/>
</form>