problem in selecting second arraylist from mysql database

Ads
 

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");

Ads









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
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
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
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
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
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
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
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
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
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
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
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
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
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 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
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
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

Ads