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?

View Answers

March 29, 2011 at 12:05 PM

1)select.jsp:

<%@page import="java.sql.*"%>
<html>
     <head>
     <script type="text/javascript">
     var xmlHttp;
function showState(str){
if (typeof XMLHttpRequest != "undefined"){
xmlHttp= new XMLHttpRequest();
}
else if (window.ActiveXObject){
xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlHttp==null){
alert ("Browser does not support XMLHTTP Request")
return
} 
     var url="select2.jsp"
     url=url+"?fooditem="+str
     xmlHttp.onreadystatechange=stateChanged 
     xmlHttp.open("GET",url,true)
     xmlHttp.send(null)
     }

     function stateChanged(){ 

     if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
    document.getElementById("item").innerHTML=xmlHttp.responseText 
     }
     } 


     function GetXmlHttpObject(){
     var xmlHttp=null;
     try{
     xmlHttp=new XMLHttpRequest();
     }
     catch (e) {
     try {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
     catch (e)  {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
     }
     }
     return xmlHttp;
     }
   </script>
   </head>
   <body>
   <form name="employee">
   <br><br>
     <b>Select Food Item</b>
      <select name="name" onchange="showState(this.value);">
           <option value="-1">Select</option> 
      <%
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from items");
while(rs.next()){
    %>
   <option value="<%=rs.getString("item")%>"><%=rs.getString("item")%></option>
   <%
}
    %>
   </select>
   <div id='item'>
<b>Select Item&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</b>  
<select name='item' >
<option value='-1'></option>
</select>
</div> 
   </form>    
   </body>
   </html>

2)select2.jsp:

<%@page language="java" import ="java.sql.*" %>
<%
String fi=request.getParameter("fooditem");
String buffer="<b>Select Item&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</b>  <select>";
buffer=buffer+"<option value='"+fi+"'>"+fi+"</option>";

buffer=buffer+"</select>";
response.getWriter().println(buffer);
%>









Related Tutorials/Questions & Answers:
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
List
List  i do have one list object, i want to compare this list from database table and if match found i want to update the list
Advertisements
List
List  getting values from a form and make a list of them and store them into database
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 selected item from the database. Please help me in this regard. Your help
List interface
List interface  What is the List interface
linked list
linked list  program for single linked list
Linked list
Linked list  what is difference btw linked list in datastructure and linked list in java
List interface
List interface  Give me some of the real time examples that can be developed based on List and its implemented classes
List of mobiles
List of mobiles  which mobile phones support j2me
Java list
Java list  What is the difference between a Choice and a List
linked list
linked list   how to add student and mark and number from file in linked list and print them also how to make search function plz can help me sooon
linked list
linked list  hi i have basal problem what is the linked list
linked list
linked list   how to write a program using a linked list...); System.out.println("Add elements to LinkedList: "); LinkedList<String> list=new...); } Collections.reverse(list); System.out.println("List of names in reverse order
ModuleNotFoundError: No module named 'list-in-list'
ModuleNotFoundError: No module named 'list-in-list'  Hi, My Python... 'list-in-list' How to remove the ModuleNotFoundError: No module named 'list-in-list' error? Thanks   Hi, In your python
list and textbox
list and textbox  sir, i want to create a search, where when i type the letters, the words starting with that letters are to be searched and displayed. Also like a list i should navigate and select the appropriate word which
linked list
linked list  Hi i have a problem with linked list ! how and where i can use linked list? please give me some example.   Please visit...://www.roseindia.net/java/beginners/linked-list-demo.shtml
Linked List
in the following logical linked list represents Computer Number. 76(head) 98 54...?. The segment should also display the new contents of the linked list. ii. Write a program segment to copy all ?Dell? computers to a new linked list named
linked list
program to manage the registration details for the institute. 1. Use a linked list to manage the details of all registered students. a. Create your own linked list
Array List
Array List   Complete the class House and HouseApp below to display class House{ int lotNo; String type; //Bungalow, SemiDetached double price; public House ( int l, String t, double p) { â?¦ } public int theLotN() {
DropDown list
DropDown list  how to get mysql database values into dropdown usign java servlet and ajax?   Here is a jsp code that displays the database values into dropdown list. 1)country.jsp: (adsbygoogle
List In Java
List In Java In this section we will read about the List data structure in Java and how the List data structure can be implemented in Java. List data structure is implemented in Java using List interface. List interface allows
PHP Form Part-6 - How to Deals with Text Boxs
Topic : HTML FORM - How to Deal with Text Boxs in PHP Part - 6 In the previous part of HTML FORM tutorial, we learned how to deal with text box.ADS_TO_REPLACE_1  In this part of the tutorial we will learn how to deal with radio
pdf list
pdf list       In this program we are going to know how we can make a list in a pdf file irrespective... the document by document.open(). Create a numbered List with 30 point field
List in J2ME
List in J2ME       Exclusive List MIDlet Example This example illustrates how to create a Exclusive List. The Exclusive List is used to select only one list element at a time
List in J2ME
List in J2ME       J2ME Canvas List Example will explain you, how to create list of items. In this example we are going to create a simple list of text, that will show
ModuleNotFoundError: No module named 'list-within-list'
ModuleNotFoundError: No module named 'list-within-list'  Hi, My... named 'list-within-list' How to remove the ModuleNotFoundError: No module named 'list-within-list' error? Thanks   Hi, In your
Merge two list into a single list
list. Here you find mainly three function. The insertnode function makes node... and the mergelist funtion merge the two lists into a single list. Code: # include... ( struct node *p ) { printf("The data values in the list are\n"
Mysql List
Mysql List       Mysql List elaborate you an Query for listing databases,tables... The Tutorial illustrate an example from 'Mysql List'. To grasp this example, We
Mysql List
Mysql List       Mysql List elaborate you an Query for listing databases, tables, Procedure... The Tutorial illustrate an example from 'Mysql List'. To grasp this example, We
Java list of uninstantiated classes
Java list of uninstantiated classes  Java list of uninstantiated classes
array list example
array list example  Array list example   Hello Friend, Please visit the following links:ADS_TO_REPLACE_1 Array List Example1 Array List Example2 ThanksADS_TO_REPLACE_2
getting html list in a array
getting html list in a array  hi i want to get html unordered list in a array using jsp
getting html list in a array
getting html list in a array  hi i want to get html unordered list in a array using jsp
ultiple selections list in Struts
ultiple selections list in Struts  How to create a multiple selections list in Struts? and retrive seleted values
drop down list in Struts
drop down list in Struts  How to create a drop down list in Struts
multiple selections list in Struts
multiple selections list in Struts  How to create a multiple selections list in Struts? and retrive seleted values
ModuleNotFoundError: No module named 'as_list'
ModuleNotFoundError: No module named 'as_list'  Hi, My Python... 'as_list' How to remove the ModuleNotFoundError: No module named 'as_list... to install padas library. You can install as_list python with following command
ModuleNotFoundError: No module named 'as_list'
ModuleNotFoundError: No module named 'as_list'  Hi, My Python... 'as_list' How to remove the ModuleNotFoundError: No module named 'as_list... to install padas library. You can install as_list python with following command
ModuleNotFoundError: No module named 'list_it'
ModuleNotFoundError: No module named 'list_it'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'list_it' How to remove the ModuleNotFoundError: No module named 'list
ModuleNotFoundError: No module named 'the_list'
ModuleNotFoundError: No module named 'the_list'  Hi, My Python... 'the_list' How to remove the ModuleNotFoundError: No module named 'the_list... to install padas library. You can install the_list python with following
contains for list in struts2 - Struts
contains for list in struts2  Is there any way to check in the list or for existence of an enum ? Something like list.contains(string). iterating over list I want to do something like Display x display y
java technologies list
java technologies list  Please provide me the java technologies list
Broken link list
Broken link list   Please provide me a java code to find the broken link list of url's for a given url
What is the List interface?
What is the List interface?  Hi, What is the List interface...;The list interface is nothing but a subtype of tha java ordered collection... the behaviour of a collection that stores a sequence of elements. So the order list
Java table & list
Java table & list  I am taking string elements from user in list, And I want those list elements to be added to table row one by one, The jTable & list are at different classes but under same package. How to do so? Please
dropdown list in jsf
dropdown list in jsf  I want to add a list box to display the country name from the lists on all countries.When I select for e.g India then in the second list box it will display the states related to India only and the flow
Explain Linked List
Explain Linked List   hello, What is Linked List ?   hello,ADS_TO_REPLACE_1 Linked List is one of the fundamental data structures. It consists of a sequence of nodes, each containing arbitrary data fields pointing
Get the list of tables in Sybase
Get the list of tables in Sybase   hello, How to get the list of tables in Sybase?   hii,ADS_TO_REPLACE_1 Select name from sysobjects where type="...." it will give You list according to where clause
List files recursively in linux
List files recursively in linux  Hi, How to List files recursively in linux? I want to list all the .php file. Thanks   Hi, You can use following command: find . -name *.php -print Thanks
list - Java Interview Questions
list  Hi all Naturally in java a list will allow duplicates, but if i want the list which shouldn't allow duplicates then what should be the logic...) method of Interface List public boolean contains(Object o) Returns

Ads