-1

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>
2
Contributors
2
Replies
7
Views
6 Years
Discussion Span
Last Post by RaniaH
0

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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.