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



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


rahul
problem in selecting second arraylist from mysql database
4 Answer(s)      3 years and 11 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]


Advertisement
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. Please read at http
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
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
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
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 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 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 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
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>
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
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
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
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
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
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
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
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 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
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
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
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
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
DELETE with alias reference impossible without selecting a db since MySQL 5.5.3?
DELETE with alias reference impossible without selecting a db since MySQL 5.5.3?   DELETE with alias reference impossible without selecting a db since MySQL 5.5.3
Advertisements
 

 

 

DMCA.com