dependent drop down box

dependent drop down box

haloo sir

Please give me the solution how to extract data from dependent drop down box with page refresh, If possible please give some example for better understanding.

With regards
saroj
View Answers

May 22, 2010 at 3:10 PM

Hi Friend,

Try the following code:

<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<script>

function change(){
var cid=document.getElementById("book").selectedIndex;
var val = document.getElementById("book").options[cid].text;
window.location.replace("http://localhost:8080/examples/jsp/dependentDropdown.jsp?id="+cid+"&&value="+val);
}
function extract(){
var ide=document.getElementById("info").selectedIndex;
var bookname = document.getElementById("info").options[ide].text;
window.location.replace("http://localhost:8080/examples/jsp/dependentDropdown.jsp?book="+bookname);
}
</script>
<%!
Connection conn = null;
ResultSet rs =null;
Statement st=null;
String query="";

%>
<%
String value=request.getParameter("value");
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root";, "root");
st = conn.createStatement();
rs = st.executeQuery("select * from book");
%>
<select id="book" onchange="change();">
<option value="0">--Please Select--</option>
<% while(rs.next()){ %>
<option value="<%=rs.getString("books")%>"><%=rs.getString("books")%></option>
<% if(rs.getString("books").equals(value)){%>
<option value="<%=value%>" selected disabled><%=value%></option>
<%
}
}
%>
</select>
<select id="info" onchange="extract(this)">
<option value="0">--Please Select--</option>
<%
String id=request.getParameter("id");
rs=st.executeQuery("select * from bookInformation where bookid='"+id+"'");
while(rs.next()){
%>
<option value="<%=rs.getString("id")%>" ><%=rs.getString("booknames")%></option>
<%
}
%>
</select>
<%
String book=request.getParameter("book");
String author="";
String price="";
rs=st.executeQuery("select * from bookInformation where booknames='"+book+"'");
while(rs.next()){
author=rs.getString("writer");
price=rs.getString("price");
}
if((book!=null)&&(author!=null)&&(price!=null)){
%>
<table >
<tr><td>Book Name</td><td><input type="text" value="<%=book%>"></td></tr>
<tr><td>Author</td><td><input type="text" value="<%=author%>"></td></tr>
<tr><td>Price</td><td><input type="text" value="<%=price%>"></td></tr>
</table>
<%
}
%>
</body>
</html>

For the above code, we have used following database tables:

1)book

CREATE TABLE `book` (
`bookid` bigint(20) NOT NULL auto_increment,
`books` varchar(255) default NULL,
PRIMARY KEY (`bookid`)
)

2)bookinformation

CREATE TABLE `bookinformation` (
`id` bigint(255) NOT NULL auto_increment,
`bookid` int(255) default NULL,
`booknames` varchar(255) default NULL,
`writer` varchar(255) default NULL,
`Price` double default NULL,
PRIMARY KEY (`id`)
)

Thanks









Related Tutorials/Questions & Answers:
dependent drop down box - JSP-Servlet
dependent drop down box  haloo sir Please give me the solution how to extract data from dependent drop down box with page refresh, If possible please give some example for better understanding
Dependent drop down list
Dependent drop down list  hi,i am trying to design a form on which 2 dependent drop down list is used my code is successful but when i select class from first drop down list all the data get lossed means the value entered
Advertisements
JSP Dependent Drop Down Menu
JSP Dependent Drop Down Menu  Hey Guy/Gals! I need someone help to guide me in creating a drop down menu, where the first menu affects the second...; The given code will help you to create a dependent dropdown box. 1
Drop Down Box
Drop Down Box  In a Drop Down box I want to show the user All the Country In the World. And when he type A-z,then each of the type Show those country which start with those word. Like I For-India
drop down box - JSP-Servlet
drop down box  when i enter some letter in the input box,the corresponding words of that particular letter must be displayed below as a list from the data base in the same input box as drop down. Thanks&Regards, VijayaBabu.M
store values of drop down list box in database
store values of drop down list box in database  how to store values of drop down list box in oracle database in jsp?I have information inserting form where i have date of birth as drop down list box
How to create a dependent drop down list using [Apache POI]
How to create a dependent drop down list using [Apache POI]  Here I..., and "rice, curd, milk" items will appear in the dependent drop down list in cell.... In that two drop down list are there. Want to create a drop down list that depends
How to create a dependent drop down list using [Apache POI]
How to create a dependent drop down list using [Apache POI]  Here I..., and "rice, curd, milk" items will appear in the dependent drop down list in cell.... In that two drop down list are there. Want to create a drop down list that depends
dynamic drop down list box - Java Beginners
dynamic drop down list box  hi all , I want to dynamically populate a drop down box from an sql query in a servlet program, using only html & javascript. Is this possible without some kind of server side code? If so, please
how to import values from database to the drop down box
how to import values from database to the drop down box   hi iam... employee page i kept a drop down box for employee Ids i want all employee IDs will display in the drop down box please help me with the code
retrive the data from access database to drop down list box in jsp
retrive the data from access database to drop down list box in jsp  hai, im new to jsp now im using the jsp along with access database.in table i load all the data's i need to retrive the data from database to dropdown list box
jsp login code ... when username , drop down box and password is correct
jsp login code ... when username , drop down box and password is correct  i need a jsp code for login.... when username password and dropdown box value is correct.... the drop down box values should be retrieved from database
jsp code for a drop down box to retrive value from database
jsp code for a drop down box to retrive value from database  my project needs to get the value from database in to the drop down box..... pls give me code for that ..... tan q   1)login.jsp: <html> <script>
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can you help me out !!.......i wanna to know the appropriate java syntax to insert data into database using an drop down box .....as i m using eclipse as jdbc
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can you help me out !!.......i wanna to know the appropriate java syntax to insert data into database using an drop down box .....as i m using eclipse as jdbc
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can you help me out !!.......i wanna to know the appropriate java syntax to insert data into database using an drop down box .....as i m using eclipse as jdbc
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can you help me out !!.......i wanna to know the appropriate java syntax to insert data into database using an drop down box .....as i m using eclipse as jdbc
Drop Box
Drop Box  program draw 2d shapes in java
Drop Box
Drop Box  program draw 2d shapes in java
drop down
drop down  how can i add data from choice/dropdown component of java awt to myaql table
Drop Down
Drop Down  How to insert date into database using dropdown like facebook
Drop Down reload in IE
Drop Down reload in IE  Hi i was using two drop down box..One for Displaying date followed by another for Dispalying Month..If i Select/Change Month from the 2nd drop down then the 1st drop down ( which is date) automatically
drop down menu
drop down menu  drop down menu using html
drop down list in Struts
drop down list in Struts  How to create a drop down list in Struts
dynamic drop down list
dynamic drop down list  I want to create 2 drop down list, where it takes value from database and the two list are dependent..means if I select a particular value from one the other list is developed accordingly..depending
Login With Drop Down
box and then login to the page. I have a drop down list box with Customs... by selecting the drop down box. Suppose the Customs username is 1001 and Accounts... using the drop down box and the Username and passwords must match with the Database
Drop down menu
Drop down menu  I have drop down list of some 14 links which links to the table,If i click each link the table should display below the link and again if i click the link the table should not appear. please help me
Drop down menu
Drop down menu  I have created a drop down list of links which links to a table but if i click the link the table display in the other page i want to display it in the same page.Please tell me the solution
validation for drop down list
validation for drop down list  Hi all I have a form, it contain 12 drop down list. Each drop down has 1 to 5 values,i need to validate this form. the following condition should be true. 1.you can choose only 3 times 5 value. 2
Get values in drop down list
in drop down box in front end..... pls provide me code.. thanx...Get values in drop down list  Pls provide me jsp code to get values in drop down list from another table's field. my project has customer
Ajax drop down and textbox
Ajax drop down and textbox  hie frnds I have a dropdown menu in the 3 options(1,2,3) are there if i choose 1 then I should get 1 text box if i select... the dropdown box, the corresponding number of textboxes will get displayed on the browser
dynamic drop down
dynamic drop down   I have created 2 drop downs in jsp.1 for department and other for its related designation.that means if I select a department... into the designation drop down (use jsp+javascript+servlet) reply soon   1
Drop down combos
Drop down combos  Hi.. How to write a javascript for linked combo dropdown boxes.   <html> <h2>ComboBox</h2> <script language="javascript"> var arr = new Array(); arr[0] = new Array("-select
Drop down for search textbox like google search
Drop down for search textbox like google search  I want drop down... with that are displayed). when the drop down list appear, then we can select one of word as our text box value. Thanks in advance
drop down php mysql - PHP
drop down php mysql  PHP Script required to show the similar drop down item in each menu without refreshing the page. Is it possible if yes how
Select functionality of drop down list - Struts
have Drop down list having element Test1,Test2,Test3,HIDE and one Text msg box...Select functionality of drop down list  Hi, I have to write a code(in struts application) in which if user select HIDE from the drop down list
Drop Down Reloads again in IE..How to prevent this?
Drop Down Reloads again in IE..How to prevent this?  Hi i was using two drop down box..One for Displaying date followed by another for Dispalying Month..If i Select/Change Month from the 2nd drop down then the 1st drop down
Dependant & dynamic drop down list
Dependant & dynamic drop down list  I don't know this should be in this or AJAX forum. I have one dynamic drop down list from data base (working... on the values selected by user in first drop down list. How to achieve this ?   
Drop down list from database
Drop down list from database  Hi, Can I know how do we get the drop down list from database? Eg: select country--select state--select district--so on.   1)country.jsp: <%@page import="java.sql.*"%> <html>
jsp drop down-- select Option
jsp drop down-- select Option  how to get drop down populated dynamically   Hi Friend, Create table country(country_id,country) in database and try the following code:ADS_TO_REPLACE_1 <%@page import="java.sql.
html menu button drop down
html menu button drop down  How to create a menu button in HTML?   <select id="category"> <option value="1">One</option> <option value="2">Two</option> </select> <select id
Login With Drop Down, Having Departments in different table
is to select the department from the drop down box and then login to the page. I have a drop down list box with Customs and Accounts..A Username and a Password field.Now want to login to the page by selecting the drop down box. Suppose
dynamic creation of multiple drop-down menus
dynamic creation of multiple drop-down menus  can anybody plz help me in coding for dynamic creation of multiple drop-down menus in a webpage using ajax/js/html/css
jQuery Drop Down Menu
jQuery Drop Down Menu       In this JQuery tutorial we will develop a program  to make Drop Down menuADS_TO_REPLACE_1 Steps to develop the Drop Down menu . Step 1:  ADS
jsp drop down without refresh - JSP-Servlet
jsp drop down without refresh  Sir I have tried two depenedent jsp dropdown in jsp page,But the probleam is when i select first drop down its... jsp same probleam also arise. Please tell me how to use the drop down without
Passing Multi select list box values using ajax to get values to dependent list box
Passing Multi select list box values using ajax to get values to dependent list box  Hi, I have a jsp page which has 3 dependent list boxes... the dependent values to the immediate next list box. Please help me
Drop-down text selection in jsp/html
Drop-down text selection in jsp/html  Hi, I am trying to create JSP page where I have two drop-downs. There are two-sets of data - First set.... Now the first dropdown will have all the values. The second drop-down depends upon
Display related data in other drop down list on selecting one data in one drop down list
Display related data in other drop down list on selecting one data in one drop down list  How to display related datas in dropdown list from database on selecting one data in previous dropdownlist in Java Server Page
Drop down and radio button value on edit action
Drop down and radio button value on edit action  HI, I have a title field and a payment type field for title i have used drop down with values mr.,mrs.,miss for payment type there are to radio buttons as by cash &
Dependant & dynamic drop down list - Follow up
Dependant & dynamic drop down list - Follow up  Thanks for your answer. As per your answer This will select only ONE row (country) from first drop down. In my case user can choose more than one row , which is then sent to next

Ads