combobox
In dashboar.jsp form, When i click employee id value in combo box ,the related employee name will be displayed in text field...
i already stored combo box values from database.
can u pls tell me the proceduer to get data from my sql database
View Answers
January 28, 2011 at 11:19 AM
Hi Friend,
Try this:
1)ajax.jsp:
<%@page import="java.sql.*"%>
<html>
<head>
<script type="text/javascript">
function showData(value){
xmlHttp=GetXmlHttpObject()
var url="getdata.jsp";
url=url+"?id="+value;
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged(){
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
var showdata = xmlHttp.responseText;
document.getElementById("name").value= showdata;
}
}
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>
<table >
<div id="mydiv"></div>
<tr><td><b>Select ID:</b></td><td>
<select id="sel" name="sel" onchange="showData(this.value);">
<%
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from employee");
while(rs.next()){
%>
<option value="<%=rs.getInt("id")%>"><%=rs.getInt("id")%></option>
<%
}
%>
<tr><td ><b>Address:</b></td><td>
<input type="text" name="name" id="name" ></td></tr>
</table>
</form>
</body>
</html>
2)getdata.jsp:
<%@ page import="java.sql.*" %>
<%
int id = Integer.parseInt(request.getParameter("id").toString());
System.out.println(id);
String data ="";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from employee where id="+id+"");
while(rs.next())
{
data =rs.getString("name");
}
out.println(data);
System.out.println(data);
}
catch (Exception e) {
System.out.println(e);
}
%>
Thanks
January 28, 2011 at 11:34 AM
Ads
Related Tutorials/Questions & Answers:
comboBox validation
comboBox validation dear sir.
i want to know . how to validate radio button in struts using xml validation.
thanks
Advertisements
Flex Combobox
Flex Combobox flex
combobox with database as dataprovider
You can visit the following link for detailed tutorial on the topic. May this will be helpful to you.
http://www.roseindia.net/flex/flex-combo-box.shtml
Flex Combobox
Flex Combobox flex
combobox with database as dataprovider
 ... backgroundColor = '#CCCCFC' width =
'100%' height = '100%'>
<mx:
ComboBox...;
<mx:
ComboBox x = '200' color = 'green'>
<mx:dataProvider>
jsp combobox
jsp combobox ihave three tables in database country,state and city..if i select one country throug combo box than other
combobox show state only select country ...than city how i can implement through jsp
1
editable combobox method selection
editable
combobox method selection how to make an editable
combobox that shows nothing initially but as a key is pressed it pops up and selects an item starting with that letter, subsequent keys would keep sorting from the list
how to use an editable combobox
how to use an editable
combobox Hello Everyone!!!!!!!!
I have a jcombo box with certain values and i want to use it as an editable that means when user will type something in
combobox, according to that text only matching item
fill combobox at runtime jsp
fill
combobox at runtime jsp i have 1
combobox in jsp which... another
combobox below it, i want it to be filled on the basis of selected value of 1st
combobox...plz help with code
two linked combobox
two linked combobox give jsp example of two combo box when i select state in one
combobox in second combo box cities will display according to state which i select
combobox cannot be resolved in JavaFX
combobox cannot be resolved in JavaFX I want to design one application with a
combobox containing items. and while selecting i want to give user autocomplete suggestion. but while doing this
combobox is not getting resolved. i
Combobox jsp from 0 to 10
Combobox jsp from 0 to 10 Hi guys please help me to write a very easy program using jsp to display value in
combobox from 0 to 10. How to write the for loop? Please help.Thank!!!
<html>
<select>
<
how to select second combobox value .
how to select second
combobox value . I requirement is ,
i have two combo box, i am selected first combo box value then automatically second combo box value show ,But this both combo box value i retrieves in database.
please
Combobox in HTML
Combobox in HTML is used to display a drop-down list of some options from which one can be selected.
<select> tag is supported in all the web browsers... the options in the list.
Here is how to make a simple
Combobox in HTML:
<html>
Example of struts2.2.1 combobox tag.
Example of struts2.2.1
combobox tag.
In this tutorial, you will see the implementation of struts2.2.1
combobox
tag. The
combobox is basically an HTML INPUT... it in directly in the text field.
Directory structure of
combobox tag
java code using combobox,radiobutton,checkbox
java code using
combobox,radiobutton,checkbox hi, send me java code for entering student details into ms access database, the code should includes combo box,radiobutton and checkboxes pl send as early as possible
Displaying data from combobox on the web page
Displaying data from
combobox on the web page Sir, I have to make a project in which a data from the database is to be displayed in combo box and depending on the choice made in combo box the data pertaining to it from
Displaying data from combobox on the web page
Displaying data from
combobox on the web page Sir, I have to make a project in which a data from the database is to be displayed in combo box and depending on the choice made in combo box the data pertaining to it from
Displaying data from combobox on the web page
Displaying data from
combobox on the web page Sir, I have to make a project in which a data from the database is to be displayed in combo box and depending on the choice made in combo box the data pertaining to it from
Displaying data from combobox on the web page
Displaying data from
combobox on the web page Sir, I have to make a project in which a data from the database is to be displayed in combo box and depending on the choice made in combo box the data pertaining to it from
Displaying data from combobox on the web page
Displaying data from
combobox on the web page Sir, I have to make a project in which a data from the database is to be displayed in combo box and depending on the choice made in combo box the data pertaining to it from
Jdbc Login Page Validation using Combobox
want to login by validating with
combobox....The link which you send
its.......please help me i dont know how to validate the
combobox for diffrent cities please help me by validating with
combobox....
<form action
Java swing: get selected value from combobox
Java swing: get selected value from
combobox
In this tutorial, you will learn how to get selected value from
combobox.
The
combobox provides the list... of programming languages to the
combobox using addItem() of
JComboBox class. We have
Passing values in ComboBox from XML file
Passing values in
ComboBox from XML file
In this tutorial we are going to know how we can pass a
values in
ComboBox by using XML.
This example... the data
from the XML file and insert it into the
ComboBox.
To make a program over