Forum Moderators: open
This is my first post on these boards and Im new to the world of Java and Jsp.
From reading up and looking at examples I have generated code to read an access database and populate TWO combo boxes.
At present they are not dynamic.
I would like to use the Onchange event to use the value from the first comobo box to populate the second.
Im not sure how to go about checking when the selection has changed to keep the selected value if its not of value 'no choice' and then how to use it to be passed into the SQL query which generates the second box.
Im hoping the code will explain better than my words.
I dont expect anyone to teach me jave but any tips and advice would greatly be appreciated.
Thanks
Rob
<%@ page import="java.util.*" %>
<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<HTML>
<H1>FAQ</H1>
<H3>Category choice</H3>
<FORM ACTION="wk465682UserMenu.jsp" METHOD="POST">
<%
String CategoryCombo = null;%>
<SELECT NAME="Category" id= Category onChange="location.href='wk465682UserMenu.jsp?option='+this.value;">
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:odbc:FAQ");
Statement statement = conn.createStatement();
ResultSet rs = statement.executeQuery("SELECT DISTINCT CATEGORY FROM FAQ" );%>
<OPTION VALUE='nochoice'>Please choose a category</OPTION>";
<%while(rs.next()) {
CategoryCombo = rs.getString("Category");%>
<OPTION value ="optcategory"><%out.println(CategoryCombo);%>
</OPTION>
<% } %>
</SELECT>
<BR><BR>
<H3>Question selection</H3>
<%
String QuestionCombo = null;%>
<SELECT NAME="Question" id = Question>
<OPTION VALUE='nochoice'>Please choose a question</OPTION>";
<%ResultSet ss = statement.executeQuery("SELECT * FROM FAQ WHERE CATEGORY = ( '" + CategoryCombo + "')");
while(ss.next()) {
QuestionCombo = ss.getString("Question");%>
<OPTION value="optquestion"><%out.println(QuestionCombo);%>
</OPTION>
<% }
%>
</SELECT>
</FORM>
</HTML>
This is a javascript forum, not a java forum, however there still may be some advice that I can give you. First off, google is the best way to get example code and solutions to all different programming projects. My suggestion would be to try a google search for what you are looking for, and I'm sure you'll be able to find something that can help you implement your project.