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>

Hi,
Is your application uses only JSP?
Otherwise u can use Ajax for this issue.

You can pass value to ajax request to populate another select box.

call a function on onchange event of first select box in that u can get

var selectedvalue=document.getElementByName("evnt_cat").options[document.getElementByName("evnt_cat").options.selectedIndex].value;

then pass it to AJAX request.

Thank you mamatachaudhari,
till now I'm using only JSP. I will follow you, Thanks for clear explanation :)

appreciated

Hi,
Is your application uses only JSP?
Otherwise u can use Ajax for this issue.

You can pass value to ajax request to populate another select box.

call a function on onchange event of first select box in that u can get

var selectedvalue=document.getElementByName("evnt_cat").options[document.getElementByName("evnt_cat").options.selectedIndex].value;

then pass it to AJAX request.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.