Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


praveena
jsp list box
1 Answer(s)      4 years and 3 months ago
Posted in : Java Beginners


I have two list boxs. the values for the first list box is retrieved from the mysql database. I want to fill the second list box selected item from the database.

Please help me in this regard.

Your help is highly appreciated.

Advertisement
View Answers

April 28, 2010 at 4:48 PM


Hi Friend,

Try the following code:

<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<script>
function city(){
var cid=document.getElementById("country").selectedIndex;
var val = document.getElementById("country").options[cid].text
window.location.replace("http://localhost:8080/examples/jsp/country.jsp?id="+cid+"&&value="+val);
}
</script>
<%!
Connection conn = null;
ResultSet rs =null;
Statement st=null;
String query="";
int cid;
%>
<%
String value=request.getParameter("value");

Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root";, "root");
st = conn.createStatement();
rs = st.executeQuery("select * from country");
%>
<select id="country" onchange="city();">
<option value="0">--Please Select--</option>
<% while(rs.next()){ %>
<option value="<%=rs.getString("countryname")%>"><%=rs.getString("countryname")%></option>

<% if(rs.getString("countryname").equals(value)){%>
<option value="<%=value%>" selected disabled><%=value%></option>
<%
}
}
%>
</select>
<select>
<%
String id=request.getParameter("id");
rs=st.executeQuery("select * from city where countryid='"+id+"'");
while(rs.next()){
%>
<option value="<%=rs.getString("city")%>" ><%=rs.getString("city")%></option>
<%
}
%>
</select>
</body>
</html>

For the above code, we have created two database tables:
1)'country'
CREATE TABLE `country` (
`countryid` bigint(30) NOT NULL auto_increment,
`countryname` varchar(40) default NULL,
PRIMARY KEY (`countryid`)
)

2)'city'
CREATE TABLE `city` (
`id` bigint(40) NOT NULL auto_increment,
`countryid` int(20) default NULL,
`city` varchar(40) default NULL,
PRIMARY KEY (`id`)
)

Thanks


Related Tutorials/Questions & Answers:
List Box - JSP-Servlet
list box.on selecting one value in list box,i will retrieve values from database and store into another list box in same page using javascript :location.my problem is in first list box,value which i selected to get values is not displaying
jsp list box - Java Beginners
jsp list box  I have two list boxs. the values for the first list box is retrieved from the mysql database. I want to fill the second list box...("http://localhost:8080/examples/jsp/country.jsp?id="+cid+"&&value="+val
Advertisements
Javascript List Box - JSP-Servlet
itself.my problem is in list box the semester which i selected is not showing in list box as selected.when i select,the page refreshes but i get the result what i expected.i need to show in list box as semester is selected but it doesnt
scroll bars to list box - JSP-Servlet
scroll bars to list box  Can I add scroll bars to a list box in struts?  Hi friend, Scroll the list box in struts Two attribute set "multiple" "size". Select Tag Example Select Tag
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
Dynamic loading of Combo box list using servlet - JSP-Servlet
Dynamic loading of Combo box list using servlet  I have the category... I give theortical descrption read it! Select a value from drop dwon box... and the resulst set which you getting passed into your jsp page. Then iterate
add text box and select list dynamically and get its value to store it into database using jsp request parameter
add text box and select list dynamically and get its value to store it into database using jsp request parameter  its very helpful when you have only... added select box also into next jsp page plz reply me as early as posssible
Scrolling List Box. - Java Beginners
Scrolling List Box.  How can is make a list box scrollable by using method ? Please give me the code snipetts
Scrolling List Box. - Java Beginners
Scrolling List Box.  How can is make a list box scrollable by using method ? Please give me the code snipetts
input type dialog box take text and search a list and focus that text - JSP-Servlet
input type dialog box take text and search a list and focus that text  i have a button..when i press it will prompt a dialog box with a text box... then it will search a list which contains data in the same page and if found
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
combo box - JSP-Servlet
combo box  how to get a combo box in jsp page which allows editing as well as list box
Scrolling List Box. - Java Beginners
Scrolling List Box.  How can is make a list box scrollable by using... ListSelectionListener { private JList list; private DefaultListModel listModel..."); //Create the list and put it in a scroll pane. list = new
PHP list box mysql
PHP List box that displays the data from mysql table. User can select any value from the PHP list box. Example of PHP MYSQL List Box Code <?php if(isset($_GET['roll'])) { $username="root"; $password=""; $database
PHP List Box Post
The PHP Post List box is used in the form. It contains multiple value User can select one or more values from the PHP list Box This PHP Post List Box is the alternate of Combo box PHP Post List Box Example <?php
PHP list box
The PHP List box is used in the form. It takes input values from the user. The PHP List box contains multiple values at a time. PHP List Box Example <?php      if(isset($_GET['hobbie']))   
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
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... Dynamic Combobox List
msg box in jsp
msg box in jsp  i need the source code to display the msgbox in jsp....but one condition is,i need to use it in the current page itself...now i use the message box means it prints it into another page...i need to resolve it plz
check box in jsp
check box in jsp  hey guys i am working on a web based project using jsp. In my project 1 am having 9 check boxes in 3 rows in the same form. I want to select 1 check box from each row and also i want to avoid many check box
List the names of classes used to create button and text box in Java.
List the names of classes used to create button and text box in Java.  List the names of classes used to create button and text box in Java
HI Jsp check box..!
HI Jsp check box..!  Hi all.. I want to update the multiple values of database table using checkbox..after clicking submit the edited field has to update and rest has to enable to update...please help me..its urgent
Use Ordered List In JSP
Use Ordered List In JSP   I created a Sting that contains ... . This string is generated dynamically from the db. When I place the string in the jsp, it does not create the ordered list. I can paste that string in the jsp
dropdown list in jsp
dropdown list in jsp  hai, i have static dropdown list.. i want to get the selected value in string variable without jsp regards asha
list to be displayed in jsp page.
list to be displayed in jsp page.  Can any one help me? Am developing the code in struts.I have a list in action class that has to be printed in the dropdownlist in another jsp page.Please help me in the code.. Thank u
List of checkboxes - JSP-Servlet
List of checkboxes  Hi! I making a list of time-slots with a checkbox against every such time-slot in a JSP page. My requirement is that when one or more checkboxes are checked and the delete button is clicked
combo box - JSP-Servlet
combo box  I am using a JSP form in which a combobox is given and I want to populate data in it from database and on the basis of yhe selected item I want to display related data in a textbox  Hi Friend, Create
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
remove item from list box using java script - Java Beginners
remove item from list box using java script  remove item from list box using java script  Hi friend, Code to remove list box item using java script : Add or Remove Options in Javascript function addItem
how to crate callout box in jsp - JSP-Servlet
how to crate callout box in jsp  how to create a callout box when pointing a link in jsp page like in MS-word document callout box. Please help me I want to use
List of checkboxes - JSP-Servlet
List of checkboxes  Hi! I appreciate your effort for giving the response but now it displays only the last value of ArrayList. In other words, it is now displaying just the last time slot. Also, without clicking the checkbox
Iterate list of objects on jsp page
Iterate list of objects on jsp page  Hi, I want to iterate the list of objects on jsp page using custom tags. Can you please give me one link or example? Thanks
JSP List Size
JSP List Size          JSP List Size is used to get the size of the list. The JSP List Size uses array list object to add the elements and finally
JSP Text Box properties. - JSP-Servlet
JSP Text Box properties.  How do I restrict a text box created in JSP page only for numbers.. example: I have a function something like... any such in JSP. please let me know how to do it..  Hi Friend, Try
how to insert list box in java script dynamically and elements retrieving from database like oracle
how to insert list box in java script dynamically and elements retrieving from database like oracle  Hi, how to dynamically increase size of list... insert new course in a table.. It should be seen in my list box
jsp- database dependent dropdown list
jsp- database dependent dropdown list   i want 2 dropdown list 1... suppose class a the corresponding section dropdown list should retrieve the section respective to that class from database. please help by providing the code in jsp
how to insert list box in java script dynamically and elements retrieving from database like oracle
how to insert list box in java script dynamically and elements retrieving from database like oracle  hi all, how can i insert elements into java script list box retrieving from Database. whenever I insert any element in the Db
How to obtain the selected data item from a list box when listbox contains objects wrapped under Arraylist?
How to obtain the selected data item from a list box when listbox contains objects wrapped under Arraylist?  I have a jsp page containing a list box and a text box. I am sending an Array List object from a servlet to this jsp
Auto Complete Text Box - JSP-Servlet
Auto Complete Text Box  Please help me in Aotocomplete text box code. I m a java programmer. I m working on jsp tech. please give me the code for Autocomplete text box in which the values will generate from database table
display from select box - JSP-Servlet
display from select box  I am doing a jsp project. In this jsp... selection box which is in the same page. The photos are stored...://www.roseindia.net/jsp/file_upload/ http://www.roseindia.net/jsp/file_upload
3 dropdown list from the database using JSP
3 dropdown list from the database using JSP  Hi, I'm new to JSP I want to create 3 dropdown list each depend on the other and get the options from the database using JSP
populating text box using jsp code
populating text box using jsp code  Sir, How to populate related values in a text box after selecting value from drop down list using JSP and mysql.... Please give an example using jsp code only.   dependentDropdown.jsp
how to get combo box value - JSP-Servlet
how to get combo box value  i have created 1 servlet & 1 jsp page. in servlet page i have fired query & fetched name & its id & that i have shown in combo box in jsp page: (small part of my code) "> now i want
How to retrieve data by using combo box value in jsp? - JSP-Servlet
How to retrieve data by using combo box value in jsp?  For example, In Employee.jsp form, When i click employee id value in combo box...... i already stored combo box values from database. pl
list boxs
list boxs  i have two list boxes first list box values from database and i want to assign selected options to the second list box using jsp is it possible to do this in jsp
Auto Complete Text Box - JSP-Servlet
Auto Complete Text Box - JSP-Servlet  Auto Complete Text Box Please help me in Aotocomplete text box code. I m a java programmer. I m working on jsp tech. please give me the code for Autocomplete text box in which the values
How to implement ajax in struts2 to operate on select box in jsp
by assigning to block list select box... plz help me .. its urgent .. thanx in advance...How to implement ajax in struts2 to operate on select box in jsp  I am doing a project on struts2 in which i have a jsp page which has 2 select boxes
dependent drop down box - JSP-Servlet
the solution how to extract data from dependent drop down box with page refresh...; window.location.replace("http://localhost:8080/examples/jsp/dependentDropdown.jsp?id="+cid+"&&value...; window.location.replace("http://localhost:8080/examples/jsp/dependentDropdown.jsp
How to retrieve data by using combo box value in jsp? - JSP-Servlet
How to retrieve data by using combo box value in jsp?  I am using a single jsp form.. i did not get from another form.. i do not use 2 jsp form.. all.... Note: I am using only this jsp form.. i do not use
Automatically display in text box - JSP-Servlet
Automatically display in text box  Dear Deepak Sir, When i enter some text in text box.That corresponding value in database,the value display in another text box using ajax. Thanks & Regards, VijayaBabu.M
 

 

 

DMCA.com