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



Home Answers Viewqa Java-Beginners how to populate second dropdownlist on selecting items from first one using jsp .data should be retrived from database.I prefer javascrpit.can anyone help me

Have Programming Question? Ask it here!
 
 
 


Darsana K
how to populate second dropdownlist on selecting items from first one using jsp .data should be retrived from database.I prefer javascrpit.can anyone help me
2 Answer(s)      a year and 7 months ago
Posted in : Java Beginners


how to populate second dropdownlist on selecting items from first one using jsp .data should be retrived from database.I prefer javascrpit.can anyone help me

hello everyone ' im beginner in java i want to know populating dropdownlist from db. for eg ; i hv 2 dropdowns project and mission.On loading jsp project should be populated from database.On selecting project type from dropdwon1 corresponding mission type should be loaded on dropdown2 ie,mission i hv a table proj-mission for that.


Advertisement
View Answers

December 7, 2012 at 12:26 PM


Here is an example of dependent dropdown list.

1)country.jsp:

<%@page import="java.sql.*"%>
 <html>
      <head>  
      <script language="javascript" type="text/javascript">  
      var xmlHttp  
      var xmlHttp
      function showState(str){
      xmlHttp=GetXmlHttpObject();
      if(xmlHttp==null){
       alert ("Browser does not support HTTP Request")
       return
      }
      var url="state.jsp";
      url +="?count=" +str;
      xmlHttp.onreadystatechange = stateChange;
      xmlHttp.open("GET", url, true);
      xmlHttp.send(null);
      }
      function stateChange(){   
      if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){   
      document.getElementById("state").innerHTML=xmlHttp.responseText   
      }   
      }
     function GetXmlHttpObject(){
         var xmlHttp=null;
         try{
          xmlHttp=new XMLHttpRequest();
         }
         catch(e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
      </script>  
      </head>  
      <body>  
      <select name='country' onchange="showState(this.value)">  
      <option value="none">Select</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 country");
 while(rs.next()){
     %>
      <option value="<%=rs.getString(1)%>"><%=rs.getString(2)%></option>  
      <%
 }
     %>
      </select>  
      <br>  
      <div id='state'>  
      <select name='state' >  
      <option value='-1'></option>  
      </select>  
      </div>  
      </body> 
      </html>


December 7, 2012 at 12:27 PM


continue..

2)state.jsp:

 <%@page import="java.sql.*"%>
 <%
String country=request.getParameter("count");  
 String buffer="<select name='state' ><option value='-1'>Select</option>";  
 try{
 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 state where countryid='"+country+"' ");  
   while(rs.next()){
   buffer=buffer+"<option value='"+rs.getString(1)+"'>"+rs.getString(3)+"</option>";  
   }  
 buffer=buffer+"</select>";  
 response.getWriter().println(buffer); 
 }
 catch(Exception e){
     System.out.println(e);
 }
 %>

For the above code, we have created two database tables:

CREATE TABLE `country` (                                 
           `countryid` bigint(255) NOT NULL auto_increment,       
           `countryname` varchar(255) default NULL,               
           PRIMARY KEY  (`countryid`)); 



CREATE TABLE `state` (                                   
          `stateid` bigint(255) NOT NULL auto_increment,         
          `countryid` int(255) default NULL,                     
          `state` varchar(255) default NULL,                     
          PRIMARY KEY  (`stateid`));


Related Tutorials/Questions & Answers:
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 without using any button in a table format and one more addtional question
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 without using any button in a table format and one more addtional question
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 without using any button in a table format and one more addtional question
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 without using any button in a table format and one more addtional question
how to store the data in a array retrived from the database - JSP-Servlet
in database,and i need to disply all the employees record in a single jsp. pls can any one tell me how to do it this using jsp. thankyou,  Hi nagaraj...how to store the data in a array retrived from the database  hi
how to get data from database into dropdownlist in jsp
how to get data from database into dropdownlist in jsp  Can anybody tell me what is the problem in this code as i am not able to fetch the data from... tutorial go through the link JSP Get Data Into Dropdown list From Database   
how to get data from database into dropdownlist in jsp
how to get data from database into dropdownlist in jsp  Customer Name...=con.createStatement(); String sql="select * from staff"; ResultSet rs... tell me what is the problem in this code
how to get data from database into dropdownlist in jsp
how to get data from database into dropdownlist in jsp  //Customer Name: <select name="name"> <% try{ Class.forName...="select * from staff"; ResultSet rs=st.executeQuery(sql); while(rs.next
how to output text from comboBox from first frame to textField on the second frame? please help me.. thank you in advance..
how to output text from comboBox from first frame to textField on the second frame? please help me.. thank you in advance..  how to output text from comboBox from first frame to textField on the second frame? please help me
Populate a combo box using data from a database
to populate the first one, and then how to send the data off to a servlet and preform...Populate a combo box using data from a database  Hi Guys, In need of some help, so i have three combo boxes, the first is supplier, the second
how to get data using dropdownlist, textbox and search button in jsp
how to get data using dropdownlist, textbox and search button in jsp  Hi, I want to display data using jsp,javascript and mysql. My Q. is If i select an entry suppose 'title' from dropdownlist and give a title name 'partial dif
Second tab should only show selected products from first tab
Second tab should only show selected products from first tab  In the javascript, From the comment â?? // live update of how many circlesâ?? on. The first tabâ??s form has been built manually. It is in the â?
displaying List of records from database in a jsp using ajax, onclick it should display the results ?? its urgent can u help me
displaying List of records from database in a jsp using ajax, onclick it should display the results ?? its urgent can u help me   displaying List of records from database in a jsp using ajax, onclick it should display the results
how to load value in dropdown list after selecting value from first dropdown list using javascript
how to load value in dropdown list after selecting value from first dropdown list using javascript  how to load value in dropdown list after selecting value from first dropdown list using javascript
By dropdownlist retrive data from database and show in textbox in jsp.
By dropdownlist retrive data from database and show in textbox in jsp.  Hello Sir, I am doing project in jsp.I have to retrive data from database, when I select value from dropdownlist, and that data I want to show in textbox
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 database to the dropdownlist in jsp. Example: 1st i want to display the list
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
problem in selecting second arraylist from mysql database
, but i want second list to be dynamic from database. Please, help me out. Thank...problem in selecting second arraylist from mysql database  Hi...', it should give list of that selected one in second list, BUT THAT list should be stored
Populate dropdown menu from database using jsp and servlet
Populate dropdown menu from database using jsp and servlet  please i need code to populate dropdown menu from mysql database using jsp and servlet. thanks
Values from servlet into dropdownlist in jsp page using ajax
Values from servlet into dropdownlist in jsp page using ajax  1) jsp...); } } } Im not able to get values retrived from servlet into dropdownlist of jsp page...kindly check the code attached and tell me
how to pass arraylist data from one jsp to another jsp - JSP-Servlet
how to pass arraylist data from one jsp to another jsp  hi to all iam... to receive all employee id's that are retrived from the database in the first jsp. can any one help me. ThankU  Hi nagaraj can u please send your
How to add value from sql server in dropdownlist
How to add value from sql server in dropdownlist  I have created a hospital management project using jsp servlet, where one form name is patient... id from other table like out patient, and this id will be stored dynamically
How to display data in jsp from dao using java beans?
How to display data in jsp from dao using java beans?  Hi I need to display data in jsp pulling from dao using java beans, Please can anyone give me the sample application with above topics. Any help would be highly appreciated
How to get data from DB in to Text box by using Jsp & Ajax
How to get data from DB in to Text box by using Jsp & Ajax   I want to get the data from database in to text box in a jsp page by using Ajax. If I... with a and from that i need to select the required value and i should store
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
How to export data from jsp to excel sheet by using java
How to export data from jsp to excel sheet by using java   How to export data from jsp to excel sheet by using java
How to get the data from the database using Servlet or JSP program
How to get the data from the database using Servlet or JSP program  ... database using JSP Get data from database using JSP... from the database like oracle . I have created one jsp program like this <
How to get data from Oracle database using JSP
How to get data from Oracle database using JSP  hello i have a simple... data from the database like oracle), I have created one jsp program like... the answer to retrieve data from the database by using servlet or jsp program
How to forward the control from one jsp to another?
How to forward the control from one jsp to another?  Hi... other.i.e. First JSP is communicating with the second JSP, Second JSP is not communicate with the Third JSP. I want forward the control from first jsp to second
how to get the values to dropdownlist from oracle database
how to get the values to dropdownlist from oracle database   </script> </head> <body> <select name... * from countryname"); while(rs.next()){ %> <option value="<
hello. can anyone help me with my java project, using jcreator?
hello. can anyone help me with my java project, using jcreator?  this is how it goes.. we are to develop a GUI of a certain form, in my case this one and then i should be able to create, view, search, and save using swamp.. i
how can i display the dates of one week by selecting the date randomly from the calendar?
how can i display the dates of one week by selecting the date randomly from the calendar?  I am facing a problem in my application,Here i should... the date selected from the calendar. how can we display the dates by picking
how to retrieve data from multiple tables in jsp using javabeans
how to retrieve data from multiple tables in jsp using javabeans   ...).second .java file for getting data from second table- package pack; public... for retrieving data fromm two tables : first table having fields: bookid,name
how to retrieve data from multiple tables in jsp using javabeans
how to retrieve data from multiple tables in jsp using javabeans   ...).second .java file for getting data from second table- package pack; public... for retrieving data fromm two tables : first table having fields: bookid,name
how to retrieve data from multiple tables in jsp using javabeans
how to retrieve data from multiple tables in jsp using javabeans   ...).second .java file for getting data from second table- package pack; public... for retrieving data fromm two tables : first table having fields: bookid,name
How to insert data from a combobox and textbox values into DB using JSP?
How to insert data from a combobox and textbox values into DB using JSP?  hi, How to insert a comb-box and a text box values in to DB using JSP? @DB:student; @table:stu_info; Combobox values:(class1,class2,class3); textbox1
how to load a table of data from oracle, to a jsp page using hashmap.
how to load a table of data from oracle, to a jsp page using hashmap.  I have a jsp page which ask for project ID,team name,member name according to this data i have to retrieve their details from the database(oracle). I have
how to scrape the data from one website another website using html dom parsing in php
how to scrape the data from one website another website using html dom parsing in php  " how to scrape the data from one website another website using html dom parsing in php" i'm trying this one .please provide code for me
How map the first_servlet to second_servlet - JSP-Servlet
How map the first_servlet to second_servlet  Hello, I have two questions. 1.How I want map the second_servlet by first_servlet. My Html page map..._servlet in first_servlet. Please Help me.. -Vijay.  Hi friend, Plz
retrieving of data from one jsp to another jsp - JSP-Servlet
retrieving of data from one jsp to another jsp  using jsp i m displaying a table ,in table i m displaying a radio button then values like id,name etc... that is used for different jsp please help me sir... thanks in advance   Hi
How we delete a data of database from front end jsp page
deleted from jsp page as well as from database.I used mysql and jsp. Please help me...How we delete a data of database from front end jsp page   I make a website and featch a data from data base and now i want that a delete button put
Exporting data from mysql into csv using jsp
Exporting data from mysql into csv using jsp  Hi friends.... I want to export the data from mysql to csv file using... i am having 30 columns in my... want csv file with 10 rows.. i want to do in jsp... pls help me soon..its very
How Map the First_Servlet to Second_Servlet - JSP-Servlet
of second_servlet in first_servlet. Please Help me.. -Vijay. Answers Hi...How Map the First_Servlet to Second_Servlet  My Query: Hello Sir, I... file. In Jsp have a function which define in second_servlet. How that fuction
Display related data in other drop down list on selecting one data in one drop down list
Display related data in other drop down list on selecting one data in one drop down list  How to display related datas in dropdown list from database on selecting one data in previous dropdownlist in Java Server Page
how to display data from mysql table in text box using jsp??
how to display data from mysql table in text box using jsp??  <p>hi, i have a written a code to display data from a mysql table into txtboxes... at line: 113 in the jsp file: /Cat1.jsp The local variable v_RGPC may not have
how to pass an array from one jsp to another jsp - JSP-Servlet
how to pass an array from one jsp to another jsp  hi friedns, can any One tell me how to send an array from one jsp to another jsp,pls any one send the code for this.also porvid the code how to retrive the arry in another jsp
to bring checked data from one page to another
to bring checked data from one page to another  thanks for your help... fetching data from the database on second jsp page with checkbox corresponding each... on save button then the two rows data should print on first jsp page without making
How to fetch entries/values from database to a jsp page one by one?
How to fetch entries/values from database to a jsp page one by one?  ... and data and each column has 10 enteries. I have a jsp page on which i want... what code i should write that i get each entry in each block
How to copy an jpeg image from one folder to other folder using jsp
How to copy an jpeg image from one folder to other folder using jsp  ... be in my image folder...so,How to copy an jpeg image from one folder to other folder using jsp or servlet
How to copy an jpeg image from one folder to other folder using jsp
How to copy an jpeg image from one folder to other folder using jsp  How to copy an image from one folder to another folder using jsp
 

 

 

DMCA.com