Ask Experts Questions for FREE Help !
Ask
    robtyketto's Avatar
    robtyketto Posts: 1, Reputation: 1
    New Member
     
    #1

    Feb 24, 2008, 05:21 PM
    JSP - Dynamic Combo box using SQL
    Greetings,

    I'm a beginner to jsp and from example code I have started to write the beginnings of a simple FAQ system, which allows the user to choose a question from a list of categories. Using combo boxes.

    I would like the user to select a Category and then a Question, upon which it then displays the information onscreen in an HTML table.

    Im at the point where they are populated and work statically, but I can't understand the onchange property of the select.

    I need the value in the first box to determine the value in the second combo box.

    Ideally I would like to avoid using arrays and to keep things simple as its for a university course and they don't want a complex solution (they don't expect you to have a great deal of java knowledge).

    Here is my code so far, any advice and suggestions would greatly be appreciated.
    :)

    Code:
    <SELECT NAME="Category" id= Category onChange="location.href='wk465682UserMenu.jsp?.option='+this.value;">
    Will the code above really pass in the value they have selected when reloading the jsp, it doesn't appear too.

    Thanks
    Rob

    Code:
    <!-- the % tag below is what is called a scriptlet tag - allows java to be embedded in the jsp -->
    <%@ 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><%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><%out.println(QuestionCombo);%>
    </OPTION>
    <% }
    //response.sendRedirect("wk465682UserMenu.jsp");
    //
    %>
    </SELECT>
    </FORM>
    </HTML>

Check out some similar questions!

Dvd/vcr combo to TV w/o cable box [ 3 Answers ]

Is there a way to connect a DVD/VCR combo unit that does not have a built-in tuner to a TV that has cable but doesn't have a cable box so that it can record TV programs?

DVD/VHS combo hookup to Satellite box [ 3 Answers ]

I need to hook up a DVD/VHS combo to my satellite box and do not know how? I also want to be able to record on both. Please give me step by step intrsctions. Thanks so much Sandy Walton

Combo box script [ 2 Answers ]

I was wondering if anyone has or knows where I could get a script for combo boxes that alows me to go about 6 levels in but select earlier if needed and also boxes only appears if previous box has been used.

Dynamic jsp [ 2 Answers ]

Hi:) I am doing a project where I have set up a website. I have added info into mysql. How do I dynamically get info. I have set up a clothes website, and if the customer uses drop down menus and selects "skirts" and "black" for example, how do I dynamically add the "skirts" and "black"...

Jsp [ 1 Answers ]

Hi pals I would like to know about JSP programs,how to use JSP programs etc , not the subject ,can anyone help me...


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.