problem in selecting second arraylist from mysql database

problem in selecting second arraylist from mysql database

Hi...everyone
Below i have attached my code. This code is working.....but i want some modification in that code such that when i select 'vegetable' or 'fruits', it should give list of that selected one in second list, BUT THAT list should be stored in mysql database. In the below program , i have hard-coded that second list, but i want second list to be dynamic from database.

Please, help me out.
Thank you for your help in advance

[code] <HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">


<BODY BGCOLOR=WHITE onLoad="setList(document.listsform)">

<FORM NAME="listsform">
<SELECT NAME="list1" onChange="setList(form)">
<OPTION>Fruit
<OPTION>Vegetables

<SELECT NAME="list2">
<OPTION>
<OPTION>
<OPTION>
<OPTION>
<OPTION>
<OPTION>
<OPTION>
<OPTION>
<OPTION>




[/code]

View Answers

December 20, 2010 at 12:49 PM

Hi Friend,

Try the following code:

1)select.jsp:

<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> 
   <option value="fruit">Fruits</option>
   <option value="vegetable">Vegetables</option>
   </select>

   <div id='item'>
<b>Select Item          </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          </b>  <select><option value='-1'>Select Item</option>";
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select * from items where fooditem='"+fi+"' ");
while(rs.next()){
buffer=buffer+"<option value='"+rs.getString("item")+"'>"+rs.getString("item")+"</option>";
}
buffer=buffer+"</select>";
response.getWriter().println(buffer);
%>

3)For the above code, we have created following table:

CREATE TABLE `items` (                                    
          `id` bigint(255) NOT NULL auto_increment,               
          `fooditem` varchar(255) default NULL,                   
          `item` varchar(255) default NULL,                       
          PRIMARY KEY  (`id`)                                     
        )

Thanks


December 20, 2010 at 1:11 PM

Hey thank you very very much.....I want same answer which you have posted..Thanks a lot:-)


December 20, 2010 at 5:59 PM

in above code , please i want some modification.....i have tried my best ,but i didn't get.

I want to print checked checkbox on same page in another table. please, help me out

2)select2.jsp

print("code sample");

<%@page language="java" import ="java.sql.*" %> <% String fi=request.getParameter("fooditem"); String buffer="Select Item "+rs.getString("item")+""; } buffer=buffer+""; response.getWriter().println(buffer); %>


December 20, 2010 at 6:00 PM

print("code sample");









Related Tutorials/Questions & Answers:
problem in selecting second arraylist from mysql database
problem in selecting second arraylist from mysql database  Hi... in mysql database. In the below program , i have hard-coded that second list, but i want second list to be dynamic from database. Please, help me out. Thank
selecting data from database
selecting data from database  how to select data from database using Dao in struts   Hi, You have to load the data from database using hibernate and send the data in a Java file object to jsp page.ADS_TO_REPLACE_1
Advertisements
display data from database on selecting option of dropdownlist
display data from database on selecting option of dropdownlist   Sir I want to display data from database by just selecting option of dropdown list... is that to display image from database in a grid format or in a fixed column and row
display data from database on selecting option of dropdownlist
display data from database on selecting option of dropdownlist   Sir I want to display data from database by just selecting option of dropdown list... is that to display image from database in a grid format or in a fixed column and row
display data from database on selecting option of dropdownlist
display data from database on selecting option of dropdownlist   Sir I want to display data from database by just selecting option of dropdown list... is that to display image from database in a grid format or in a fixed column and row
display data from database on selecting option of dropdownlist
display data from database on selecting option of dropdownlist   Sir I want to display data from database by just selecting option of dropdown list... is that to display image from database in a grid format or in a fixed column and row
Problem in accessing data from Database
Problem in accessing data from Database  hi..... i'm making a project on servlet and jsp with ms access 2007 at the backend. One field in my database... someone plz help me out with this problem
problem in setting the values from database
problem in setting the values from database  hello friends, can anyone help me?? I am facing this problem for past one week. I could't set the values from database. here is the code: private JTextField getJTextField1
Problem in uploading image to to mysql database
Problem in uploading image to to mysql database  Hi, need some help... the record to mysql database. heres my code... index.jsp <%@ page... be save in the database. and the image will also save in the desired folder. i
Problem in uploading image to to mysql database
Problem in uploading image to to mysql database  Hi, need some help... the record to mysql database. heres my code... index.jsp <%@ page language... be save in the database. and the image will also save in the desired folder. i
Selecting a radio button in jquery autocomplete from database value
Selecting a radio button in jquery autocomplete from database value  I can get the data from the database using PDO to my jquery.js file. How do I force the value (1 = Handicap, 2 = Scratch, 3 = Both) to select the appropriate
Selecting particular data from multiple tables at database and perfoming calculations
Selecting particular data from multiple tables at database and perfoming calculations  Hi fnds, I want to maintain the financial database of 20 users for 1 year and update the details in jsp page.. so i have decided
retrieve data from mysql database
retrieve data from mysql database  hi am not familiar in php.....even... selected value on combobox which is to be retrieve the relevant data from mysql database using php.... below my code is that.. <html> <head>
Problem with arraylist
Problem with arraylist  I am currently working on a java project and there is an if loop within the for loop.... for(int i = 1;i < iterationsNo.... It seems that problem
Repairing mysql database from command line
Repairing mysql database from command line  Hi, Can anyone tell me the process for repairing mysql database from command line? Thanks
Data retrieve from mysql database
Data retrieve from mysql database  Hi sir, please give some example of jsp code for retrieving mysql database values in multiple dropdown list... from the dropdown, related data will get displayed on the textboxes. Here we have
How to retrieve image from mysql database in JSP?
How to retrieve image from mysql database in JSP?  Hi, I need JSP same codes for learning to get image which is stored in MySQL Database. How to retrieve image from mysql database in JSP? Thanks   Hi, You can write
How to access (MySQL)database from J2ME?
How to access (MySQL)database from J2ME?  I am new to J2ME. I am using NetBeans. Can anyone help me? How to access (MySQL)database from J2ME? ( I search a lot I found that there is need to access database through servlet
arraylist problem - JSP-Servlet
correctly from database but not showing in frontend plz plz help me out ...arraylist problem  hello thanx a lot for ur reply. i m sending u my code once again only in which i m facing the problem. /* * To change
retrieve data from mysql database and store it in a variable ?
retrieve data from mysql database and store it in a variable ?  sir... that retrieve the integer values from the database and stored in the integer... which is stored in mysql. so to apply some arithmetic operation on it we have
MySql Databse query to fetch results from database
MySql Databse query to fetch results from database  Hi. I have a field in database named stages. its datatype is varchar(60). It contains values chennai,trichy,kanchipuram for a single record. I have to retrieve these data from
How to Display next Record from Database "On the Click of Next Button" USING ARRAYLIST
How to Display next Record from Database "On the Click of Next Button" USING ARRAYLIST  How to Display next Record from Database "On the Click of Next Button" USING ARRAYLIST,please send answer as soo as possible
arraylist problem - JSP-Servlet
arraylist problem  in my following code i have used a condition...="SELECT Name,Code,Team_Leader from sample1.dbo.Registration... end) AS Total_Calls from sample1.dbo.check5 where convert(varchar(10),[date],101
arraylist problem - Java Beginners
arraylist problem  Hello.... I wrote the following code for adding... the string array... But there's a problem with this... import java.util....{ ArrayList al = new ArrayList(); for(int i=0;i<10;i++){ String event
problem from registering a data in database with servlet - JSP-Servlet
problem from registering a data in database with servlet  Hi Rose, i created a servlet to validates ten user details in the database, if present...); System.out.println("Connected to the database"); String query1="Select * from user
Arraylist from row values
Arraylist from row values  Hello, can anyone please help on how to make an arraylist from the row values of a particular column from a database... = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root
dynamic retrivel of data from mysql database in table format at jsp
dynamic retrivel of data from mysql database in table format at jsp  ... the data from database and display it as table format in jsp... For example, i have... of A1 should be retrived from database and display it in the respective textbox
image is display from path of mysql database
image is display from path of mysql database  <%@ page import="java.io.,java.sql.,java.util.zip.*" %> <% String saveFile=""; String...;% Connection connection = null; String connectionURL = "jdbc:mysql://localhost
sending data to google chart api from mysql database using java
sending data to google chart api from mysql database using java  how to send data from mysql database to google chart api using java
ArrayList problem - JSP-Servlet
ArrayList problem  Hi, How can I add elements of an ArrayList to HTML combobox or list in java? Hi, You can use the following code: Array List..." name="MYLIST"> <% ArrayList a_list = new ArrayList
how to create a php script to download file from database mysql
how to create a php script to download file from database mysql  how to create a php script to download file from databse mysql
how to create a php script to download file from database mysql
how to create a php script to download file from database mysql  how to create a php script to download file from databse mysql
how to store JTree data hierarchically in mysql database from netbeans
how to store JTree data hierarchically in mysql database from netbeans  how to store JTree data hierarchically in mysql database from netbeans. I am new to this topics so I need a program and tables you are using in database
How to retrive a particular record from database in php with mysql?
How to retrive a particular record from database in php with mysql?  Am using phpMyAdmin Database.In mysql database having 10 records. The field... record based on username and password. I dont know how to retrive in php with mysql
how to display image and text in single jsp page from the mysql database
how to display image and text in single jsp page from the mysql database  hello please help me to display the image and text in single jsp page from mysql database if have any reference code please send me Thanks in advance
simple code to login user & authenticate it from database mysql
simple code to login user & authenticate it from database mysql  Sir, I am creating a login page which contain userid & password. Iwant to authenticate user from mysql database. please tell me the code for it. Thanks
retrieve related data from database using jsp and mysql
retrieve related data from database using jsp and mysql  Hi sir, please give some example of jsp code for retrieving mysql database values in multiple dropdown list. if we change a value in a dropdown its related value must
retrive the employee details with image from mysql database using jsp servlet
retrive the employee details with image from mysql database using jsp servlet  im doing the web project to retrive the employee profile which i stored in the database using jsp servlet then want to show the result in the next jsp
adding multiples markers to google map from a mysql database
adding multiples markers to google map from a mysql database   hello... are strored in table called appreciation in a mysql database. i followed sevrel..._query("SELECT * FROM appreciation"); while ($row = mysql_fetch_array
adding multiples markers to google map from a mysql database
adding multiples markers to google map from a mysql database   hello... are strored in table called appreciation in a mysql database. i followed sevrel..._query("SELECT * FROM appreciation"); while ($row = mysql_fetch_array
adding multiples markers to google map from a mysql database
adding multiples markers to google map from a mysql database   hello... are strored in table called appreciation in a mysql database. i followed sevrel..._query("SELECT * FROM appreciation"); while ($row = mysql_fetch_array
adding multiples markers to google map from a mysql database
adding multiples markers to google map from a mysql database   hello... are strored in table called appreciation in a mysql database. i followed sevrel...()); ?> <? $query = mysql_query("SELECT * FROM
Data needs to be gathered in XML file from the database (MySql) using JSP
Data needs to be gathered in XML file from the database (MySql) using JSP ... data regarding particular id from the database table. Data needs to be gathered in XML file from the database (MySql) using appropriate JSP/Java Bean functions
database problem
database problem  I did connect my jsp page to database and it showed the result on another jsp page but i want to show the data of that field on which i click to mouse from the jsp page where all the data field has been showed
database problem
database problem  I did connect my jsp page to database and it showed the result on another jsp page but i want to show the data of that field on which i click to mouse from the jsp page where all the data field has been showed
dynamic retrival of data from mysql database to dropdownlist in jsp
dynamic retrival of data from mysql database to dropdownlist in jsp  Hello, Am having problem in my project... i want to retrive the data from mysql... name from the mysql database to the dropdownlist.if the user select the particular
MySql Databse query to fetch results from database and display it in HTML File
MySql Databse query to fetch results from database and display it in HTML File  Hi. I have a field in database named stages. its datatype is varchar... to retrieve these data from the field table. Actually they are separated by comma
problem in database
problem in database   thanks for web site. I want change this code to insert data into PostgreSql database using jsp,servlets. but i getting...){ out.println("Couldn't load database driver: " + e.getMessage()); } catch
how to retrive the particular data from database in php with mysql?
how to retrive the particular data from database in php with mysql?  ..._db("samp", $con); $Name=$_POST['unames']; $data=mysql_query("SELECT * FROM tbl... like this.. <?php $con = mysql_connect("localhost","root
Retrieve image from mysql database through jsp
Retrieve image from mysql database through jsp... to retrieve image from mysql database through jsp code. First create a database... Note : In the jsp code given below, image will be retrieved from database

Ads