Ask Experts Questions for FREE Help!
  Advanced
Register  |  Log in  
   Ask    
 Answer  
  Help  

Ask QuestionsprogressAnswer QuestionsprogressBuild ReputationprogressBecome an Expert
 
Free Answers in 3 Easy Steps

Register Now
3 Steps

At Ask Me Help Desk you can ask questions in any topic and have them answered for free by our experts. To ask questions or participate in answering them you must register for a free account. By registering you will be able to:
  • Get free answers from experts in any of our 300+ topics.
  • Accept money for answers that you provide.
  • Communicate privately with other members (PM).
  • See fewer ads.

Home > Computers & Technology > Programming > Scripting > Javascript   »   JSP - Dynamic Combo box using SQL

 
Question Tools Search this Question Display Modes
Question
 
 
#1  
Old Feb 24, 2008, 03:21 PM
robtyketto
New Member
robtyketto is offline
 
Join Date: Feb 2008
Posts: 1
robtyketto See this member's comment history on his/her Profile page.
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 cant 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 dont want a complex solution (they dont 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 doesnt 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>

Reply With Quote
 
     



Question Tools Search this Question
Search this Question:

Advanced Search
Display Modes

 
Similar Sponsors

Similar Questions
Question Asker Topic Answers Last Post
dvd/vcr combo to tv w/o cable box superal Electronics 1 Feb 2, 2008 11:48 AM
DVD/VHS combo hookup to Satellite box sandywalton Television 3 Sep 5, 2007 12:51 PM
Combo box script phoenix1664 Java 2 Apr 10, 2007 12:58 AM
dynamic jsp sarah11282 Utilities 2 Feb 24, 2006 12:25 AM
jsp STRANGER_OF_UR_DREAMZ Internet & the Web 1 Feb 8, 2006 07:23 AM




Copyright ©2003 - 2007, Ask Me Help Desk.
All times are GMT -8. The time now is 01:58 PM.

Content Relevant URLs by vBSEO 3.0.0 RC6 © 2006, Crawlability, Inc.