Home Answers Viewqa JavaScriptQuestions problem in selecting second arraylist from mysql database

 
 


rahul
problem in selecting second arraylist from mysql database
4 Answer(s)      2 years and 5 months ago
Posted in : JavaScript Questions

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 Pages:
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. Please read at http
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
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
second selectbox of dynamic
="SELECT DISTINCT address_city FROM vtiger_users"; $result=mysql_query($query); if(!$result) die("database access failed:" . mysql_error()); while($row = mysql..."; $result1=mysql_query($query1); if(!$result1) die("database access failed:" . mysql
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 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
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
MySQL Creating and Deleting Database
MySQL Creating and Deleting Database   ... and delete the database in MySQL. MySQL provides the both commands. In this section you... you don't have the privilege for.  Creating And Selecting a Database
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
Database problem - WebSevices
simple database connectivity code. if you have any problem then send me detail...Database problem  Hello, How i connect my database file...:mysql://192.168.10.211:3306/"; String db = "amar"; String driver
Retrive values from an arraylist and display in a jsp?
Retrive values from an arraylist and display in a jsp?  Hi, I need help in jsp to display values of an ArrayList in jsp. There is a java file...") != null) { Open connection to the database; Read parameters from
query regarding arraylist
program. i have a problem of fetching data from the table in database. i m storing my keys in arraylist, now i want to get data according to that keys. keys are ids in database. The corresponding data should be displayed on click of an item
Connecting to MYSQL Database in Java
Connecting to MYSQL Database in Java  I've tried executing the code... from database"); } catch (Exception e) { System.out.println("Error... please help here coz I have tried to locate the problem but I can't find
Retrive values from an arraylist and display in a jsp?
Retrive values from an arraylist and display in a jsp?  Hi, I need help in jsp to display values of an ArrayList in jsp. There is a java file...") != null) { Open connection to the database; Read parameters from
How to use Arraylist object in <s:dobleselect> .... struts 2? - Struts
object with that tag. Im retrieving the values for arraylist object from database, for the first select box and on selecting the any of the item from the list... should be identified by the tag, and on selecting the item from first select box
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
database connectivity using mysql
seconds) I am using Netbeans 5.5, mysql server 5.0, to get data from table...database connectivity using mysql  java file: eg1.java package eg...[]) throws SQLException { try { String connectionURL = "jdbc:mysql
mysql query
mysql query  how do transfer into the excel data to my sql  ...). 3)After selecting the driver, click finish button. 4)Then give Data Source Name (excel) ,select drive, directory and excel file from which data
Selecting All Columns or Specific columns
to create database and create a specific columns in MySQL .  CREATE Statement... Selecting All Columns or Specific columns  ... affected (0.00 sec) MySQL creates the table by the name of Employee
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
mysql - WebSevices
a while loop it is selecting all rows from 1st table and this is writing all... into a file from 1st table and 1st row into a second line from 2nd table. I...mysql  hello all, How can I select one row at a time from 1st
arraylist
arraylist  Hi how can we eliminet duplicate element from arraylist in java? how can we achieve data abstrcation and encapulation in java? how many... Duplicates from ArryaList   Encapsulation And Abstraction   
arraylist
arraylist  Hi How can we eliminet duplicate element from arraylist? How can we find highest salary from arraylist ? How can we highest key value pair from map? Thanks Kalins Naik   Remove duplicates from Arraylist
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
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
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
java arraylist
which is having type list1 in the arraylist named list1. the problem here...java arraylist  Hi, Thanks in advance.. From the xml given below i need to create arraylist whose name is same as type value(e.g : list1,list2
arrayList
arrayList  how do i print a single index have multiple values String dist = "select distcode,distname from iwmpdistrict where stcode=29" ps = con.prepareStatement(dist
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
Data is not inserting correctly in mysql database.
Data is not inserting correctly in mysql database.  Hello Sir, below is my code to insert data into database by list iteration... static String destination; public static void main(String[] args) { ArrayList
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>
Remove checked checkboxes from arraylist and dipaly remaining arraylist
Remove checked checkboxes from arraylist and dipaly remaining arraylist ... facing proble in deleting them from arraylist and display arrylist. Please... to replace previous arraylist with new arraylist (which do not contain deleted
selecting entries
selecting entries  I have a textbox by the name country in the browser...and I have some entries of country in database like india, china, australia etc... As soon as I start to type "c" in the textbox , china should appear
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...-on-map/ the problem is that i only get the map without the markers. please help
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...-on-map/ the problem is that i only get the map without the markers. please help
to read data stored in ArrayList - Struts
create one ArrayList object and in that i have stored 4 User class objects taking them from database. Now i want to read the data of all 4 User objects from jsp...; My problem is i have to use index variable, but i am not getting how
Selecting value from autocomplete textbox using jquery in jsp
Selecting value from autocomplete textbox using jquery in jsp   hello Sir, I completed ur tutorial on autocompletion textbox from database using... to select that autosuggested value from database to textbox.plz give me
populating textbox value from the database using onchange function,
selecting from dropdownlist. i have a form in jsp n I created the dropdown list dynamically from the database(mysql). after selecting the value from the dropd...populating textbox value from the database using onchange function,  
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
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
arraylist of an arraylist
arraylist of an arraylist  Can anyone suggest me how to use arraylist of an arraylist?? how to put data into it and get data from it???? becoz i want to make rows and column dynamic which can grow as per requirement?????/ plz
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
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.