Retrieval of Dropdown list
Hi frnds... Am having problem with the below code... I have retrieved data from the mysql database into dropdownlist ... for eg, let A1,A2,A3,A4 be the values in dropdown.. if i click A1, the corresponding value of A1, list of name corresponding to A1 wil be displayed in another dropdown.. Am not able to retrive the name for further process... Pls check the below code and help me frnds.. If this code is wrong, pls help me with the proper coding... its urgent...
Update.jsp:
<script language="javascript" type="text/javascript">
var xmlHttp
var xmlHttp
function showEmp(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="SetUpdate.jsp";
url +="?groupname=" +str;
xmlHttp.onreadystatechange = stateChange;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
function stateChange(){
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
document.getElementById("name").innerHTML=xmlHttp.responseText
}
}
</script>
<table align="center" cellspacing="0">
<tr><td>Select Group:
<select name='groupname' onchange="showEmp(this.value)">
<option value="none">Select</option>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/chitfund", "root", "root");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select * from groupdetail");
while (rs.next()) {
%>
<option value="<%=rs.getString("groupname")%>"><%=rs.getString("groupname")%></option>
<%
}
%>
</select>
<br>
<div id='name'>
<select name='name' >
<option value='-1'></option>
</select>
</div> </td> </tr>
SetUpdate.jsp:
<%@page import="java.sql.*"%>
<%
String groupname = request.getParameter("groupname");
String buffer = "<select name='name' ><option value='-1'>Select</option>";
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/chitfund", "root", "root");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select * from memberdetail where groupname='" + groupname + "' ");
while (rs.next()) {
buffer = buffer + "<option value='" + rs.getString(1) + "'>" + rs.getString("name") + "</option>";
}
buffer = buffer + "</select>";
response.getWriter().println(buffer);
} catch (Exception e) {
System.out.println(e);
}
%>
View Answers
August 28, 2012 at 4:14 PM
Here is a jsp application that retrieves data from the database and stored into first dropdown. If user click any option from the dropdown, the corresponding values will get displayed into another dropdown.
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
{
// Firefox, Opera 8.0+, Safari
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>
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`));
August 28, 2012 at 5:03 PM
Related Tutorials/Questions & Answers:
Retrieval of Dropdown listRetrieval of
Dropdown list Hi frnds... Am having problem... ... for eg, let A1,A2,A3,A4 be the values in
dropdown.. if i click A1, the corresponding value of A1,
list of name corresponding to A1 wil be displayed in another
DropDown listDropDown list how to get mysql database values into
dropdown usign java servlet and ajax?
Here is a jsp code that displays the database values into
dropdown list.
1)country.jsp:
<%@page import="java.sql.*"%>
Advertisements
dropdown list in jspdropdown list in jsp hai,
i have static
dropdown list.. i want to get the selected value in string variable without jsp
regards
asha
struts dropdown list struts
dropdown list In strtus how to set the
dropdown list values from database ? I have a ArrayList object and set this object in
dropdown jsp... = MasterDataDAO.getValues(
list);
request.setAttribute("masterlist", masterList
dropdown list in jsfdropdown list in jsf I want to add a
list box to display the country name from the lists on all countries.When I select for e.g India then in the second
list box it will display the states related to India only and the flow
dropdown list and text fields in phpdropdown list and text fields in php How could I use php to populate text fields by selecting a name of a business from
dropdown list? Those text fields that will be populated by information in regards its company name, suite
getting values from dropdown listgetting values from
dropdown list I am having a
dropdown list which has hardcoded values ( we need it hardcoded only and will not be populated from the database)
My question is when i select a particular value it should be pass
how to set value of dropdown listhow to set value of
dropdown list Hello Sir, I'd solved the earlier problems somehow but now this time another problem arised when I want to pass the value from a link to a
dropdown list. I want to set the
dropdown list selected
how to set value of dropdown listhow to set value of
dropdown list Hello Sir, I'd solved the earlier problems somehow but now this time another problem arised when I want to pass the value from a link to a
dropdown list. I want to set the
dropdown list selected
jsp- database dependent dropdown list jsp- database dependent
dropdown list i want 2
dropdown list
1- CLASS
2-SECTION
both are should come from database.
and if i select a class suppose class a the corresponding section
dropdown list should retrieve the section
Dropdown Checkbox listDropdown Checkbox
list
This tutorial explains how to create jquery
Dropdown... jquery
Dropdown Checkbox
list. The application directory structure should look like...
dropdown list as checkbox
(adsbygoogle = window.adsbygoogle
getting and storing dropdown list in database in jspgetting and storing
dropdown list in database in jsp i have a drop down
list to select book from database. i'm able to retrieve
dropdown list from database. but unable to store the selected value in database table.
please help
How to add a DropDown List in Flex DataGridHow to add a
DropDown List in Flex DataGrid hi
I am trying to add... the drop down
list, the Item that I have selected is not reflected or did... select from one of the choices in the
list. That's my reason for trying to add
How to add a DropDown List in Flex DataGridHow to add a
DropDown List in Flex DataGrid hi
I am trying to add... the drop down
list, the Item that I have selected is not reflected or did... select from one of the choices in the
list. That's my reason for trying to add
help to select a value from the dropdown listhelp to select a value from the
dropdown list I have a html file called autoSuggestTextbox.html which is shown below.
<!DOCTYPE html PUBLIC... from the drop down
list created in a div and put it in the textbox
kim
dropdowndropdown how to hide textbox field when i deselect from select
dropdown dropdowndropdown I have a
dropdown having 2 options-"Open"& "closed".When i select "open" option the related rows of data are retrieved from database and same with the other option.My database is Mysql and coding in PHP
JSP Get Data Into Dropdown list From DatabaseJSP Get Data Into
Dropdown list From Database
In this section we will discuss about how to fetch data dynamically into the
dropdown list in JSP... it
into the
dropdown list dynamically. In this example we will explain the
dynamically
dropdown cacheing dropdown cacheing I need code to create cache for load drop down
list from db in struts1 example
Image retrieval in Servlet and JSPImage
retrieval in Servlet and JSP Sir, How should i give dynamic paths to image in JSP.
EX :
`<img src="C:\Users\Public\Pictures\Sample Pictures\-------.jpg" alt="" name="image5" width="980" height="320" id="" />
jsp object retrieval - Springjsp object retrieval I have a controller which calls a Service to build a
List of data from the database. I want to pass the
List to the jsp to use in rendering a grid. I know that I could pass and retrieve from the request
DropDown MenuDropDown Menu Hello,
i have a program that can view,add,delete... me draw to your my mind my program..
in my homepage which i have a
dropdown menu that has the
list of Page 1- Page 5.
if i select page 1 it will display only
dropdown boxdropdown box i need to have country,state and city in drop down box using ajax and use db2 database
Have a look at the following link:
JSP dependent
dropdown Retrieval column details into respective JComboboxs Retrieval column details into respective JComboboxs Hello sir,
As of now i created program in the Eclipse the GUI window .I had creaated... of the in GUI window,& also displayed.So now i want to make short
list to all
Dependant Dropdown ListsDependant
Dropdown Lists Hello, I'm trying to create 2
dropdown lists. When the visitor chooses one option from the 1st
list it will automatically update the 2nd
dropdown. Ive already found some code which i edited but still
creating dropdown lists in jspcreating
dropdown lists in jsp i want to create two
dropdown list which are dependent that is the first box choice have to evaluate the second boxs options
Ajax DropdownAjax Dropdown hi
I have One
Dropdown that contains 2 options assume A and B,if i select A option then samepage one more
Dropdown is their it should display values in german language
using DWRUtil Parameter values in ajax.
Only
JSON array objects retrieval in javascript JSON array objects
retrieval in javascript I am fetching some data from database and want to show these values in a combo in javascript but combo box is not populating any value, perhaps i am doing something wrong in json
Image retrieval from mysql - JSP-ServletImage
retrieval from mysql Hai friends,
I used the following code to insert image into mysql db. Db data type is blob.
Database connection codings are in different file which is to be included
jsp dropdown - JSP-Servletjsp dropdown in my table there are 3 fields named orderid ,itemname, itemqty. i want code that fetch orderid in
dropdown... on select
dropdown get all items
list of that orderid... there are multiple items at one orderid