Select from select list + display

Select from select list + display

i have a select list containing elements, say EmpCode. there are 2 fields below it EmpName and DeptName.

As i select EmpCode from the select list, the corresponding EmpName and DeptName should be displayed automatically in empty text fields.

I am using struts 1.2 framework for the application.

Kindly reply asap.

Thanks & regards.

View Answers

April 18, 2011 at 3:55 PM

1)ajax.jsp:

<%@page import="java.sql.*"%>
<html>
<head>
<script type="text/javascript">
function showData(id){ 

xmlHttp=GetXmlHttpObject()
var url="getdata.jsp";
url=url+"?id="+id;
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged(){ 
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
    var showdata = xmlHttp.responseText; 
    var strar = showdata.split(":");
    document.getElementById("name").value= strar[1];
    document.getElementById("dept").value= strar[2];
} 
}
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:</b></td><td><select 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 emp ");
           while(rs.next()){
               %>
               <option value="<%=rs.getInt("EMP_NO")%>"><%=rs.getInt("EMP_NO")%></option>
               <%
           }
               %>
               </select></td></tr>

<tr><td><b>EMP Name:</b></td><td><input  type="text" id="name" ></td></tr>
<tr><td ><b>DEPT Name:</b></td><td><input  type="text" id="dept" ></td></tr>
</table>
</form>    
</body>
</html>

2)getdata.jsp:

<%@ page import="java.sql.*" %> 
<%
int id = Integer.parseInt(request.getParameter("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 emp where EMP_NO="+id+"");
while(rs.next())
{
data =":"+rs.getString("EMP_NAME")+":"+rs.getString("DEPT_NAME");
}
out.println(data);
System.out.println(data);
}
catch (Exception e) {
System.out.println(e);
}
%>

Struts2 Ajax









Related Tutorials/Questions & Answers:
Select from select list + display
Select from select list + display  i have a select list containing... select EmpCode from the select list, the corresponding EmpName and DeptName should...=con.createStatement(); ResultSet rs=st.executeQuery("select * from emp
display from select box - JSP-Servlet
display from select box  I am doing a jsp project. In this jsp project i have to show the photos in one cell depending on the selection from other selection box which is in the same page. The photos are stored
Advertisements
Select Employee and display data from access database in a jtable
Select Employee and display data from access database in a jtable  I there Iam a java beginner. I have to create a application where I can select a employee's name from a comboBox and the jtable will be filled with all
select Query result display problem
select Query result display problem  Hi, String SQL_QUERY ="from Cc"; Query query = session.createQuery(SQL_QUERY); for(Iterator it=query.iterate... Hibernate: select cc0.id as col00 from cc cc0_ Cc$$EnhancerByCGLIB$$2235676a cannot
How to display all the Select values from the MySQL database table in where condition= In JSP?
How to display all the Select values from the MySQL database table in where... to display all the select values from MySQL DB** only first value is displayed in the jsp file. @select * from table dept where dept_no=10;" jsp code i have used
JSP:select image for db and display in image tag
JSP:select image for db and display in image tag  Hi, i am new to this forum. My query is that, i am trying to display image in tag but i am...); response.getOutputStream().flush(); } i think, this code will display image
JSP:select image for db and display in image tag
JSP:select image for db and display in image tag  Hi, i am new to this forum. My query is that, i am trying to display image in tag but i am...); response.getOutputStream().flush(); } i think, this code will display image
JSP:select image for db and display in image tag
JSP:select image for db and display in image tag  Hi, i am new to this forum. My query is that, i am trying to display image in image tag but i am...); response.getOutputStream().flush(); } i think, this code will display
how to display(update) current date and month in select box on selecting the year.
how to display(update) current date and month in select box on selecting the year.  how to display(update) current date and month in select box on selecting the year
How to display all the rows in JSP ,MySQL select condition statement IN dept_table
How to display all the rows in JSP ,MySQL select condition statement IN dept_table  I iam unable to display all the rows in JSP select statement from... is displayed.@select * from department where dept_no=10;My display code in JSP
How to Display Duplicate elements from more than one List in java?
How to Display Duplicate elements from more than one List in java?  How to Display Duplicate elements from more than one List in java? //I mean common elements from two List? Ex: List a1=new ArrayList(); a1.add(50
Display list of files from a directory using Java
Display list of files from a directory using Java In this section, you will learn how to display the list of files of a particular directory or a sub...() method display the list of file names of that directory and if it is having any
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 display records from database
how to display records from database  I want to display records from database in tables, the database is having 2000 records and i want to display 20 records at a time and to use next and previous link buttons to show
jfreechart display from access database data.
jfreechart display from access database data.  I have made a database... to retrieve the data from the access database using prepared statement and then display...="org.jfree.data.jdbc.JDBCCategoryDataset"%> <% String query="SELECT * from chart
display date to jsp from database
display date to jsp from database   display date to jsp from database to calender if the start date and end date is available than calender date will disappeared or non-clickable and its show in red color. those date
How to display content in same page while selecting fron dropdown list
dropdownlist in jsp page.If i select any value in that list(for eg-rollno),then it want to display all records from table specific to that rollno in that same...How to display content in same page while selecting fron dropdown list 
How to Display values from databse into table
How to Display values from databse into table  I want to display values from database into table based on condition in query, how to display... = request.getParameter("name"); String query = "select * from books where authorname
data are not display in JSP from database - JSP-Servlet
data are not display in JSP from database   i want to finding some data through a SQL query from SQL server database to a JSP page based on some.... one.jsp value of 'school' request parameter are comming from the link
how to display data from database in jsp
how to display data from database in jsp  how to display data from database in jsp
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
jQuery change event with multiple select option
jQuery change event with multiple select option In this tutorial , we will discuss about 'change' event of jQuery with multiple select list & it also display the selected option. In the below example a multiple select list
Display Data from Database in JSP
; <html> <head> <title>display data from...;To display all the data from the table click here...</h2></TD>...;head> <title>display data from the table using jsp</title> <
display multiple images from postgres database in jframe
display multiple images from postgres database in jframe  i just want to display multiple images on jframe by firing a query on postgres database
display the generated image from byte array - Struts
display the generated image from byte array  how to create image from byte array using struts and display it in struts html.please give me the sample code
Fetch the data from mysql and display it on php form
Fetch the data from mysql and display it on php form  when i press on login button, after succesful login the related data of that person should be display in other textbox
ModuleNotFoundError: No module named 'mult_list_display'
ModuleNotFoundError: No module named 'mult_list_display'  Hi, My... named 'mult_list_display' How to remove the ModuleNotFoundError: No module named 'mult_list_display' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'mult_list_display'
ModuleNotFoundError: No module named 'mult_list_display'  Hi, My... named 'mult_list_display' How to remove the ModuleNotFoundError: No module named 'mult_list_display' error? Thanks   Hi, In your
How to retrieve and display image from database in Java?
How to retrieve and display image from database in Java?  Hi, I am writing a web application for reading the data from database and displaying on the web page. My application is in Java/JSP. How to retrieve and display image
get and display blob from mysql on jsf
get and display blob from mysql on jsf  i want to get blob from mysql, and display on jsf page. your examples with jsp. i dont find an example with jsf. plese help me about this. thanks..   Have a look at the following
how to display a table from database using servlet
how to display a table from database using servlet  how to display a table with values from servletpage   Hi Friend, Please go through the following link:ADS_TO_REPLACE_1 http://roseindia.net/jsp/servlet-jsp-data
Display Data from Database in JSP
Display Data from Database in JSP   ... and execute query to display data from the specified table.  Before...;head> <title>display data from the table using jsp</title> <
How to read and display data from a .properties file from a jsp page
How to read and display data from a .properties file from a jsp page  I have a .properties file. I have to create a jsp page such that it reads the data from this .properties file and display it in table format. Ex:by using
Display set of names from array
Display set of names from array In this section, you will learn how to display the set of names from array. In the given code, we have declared an array... element, it will display the set of countries name from the array. Example:ADS
I want to display the quantity of the selected item of a drop down list in a textbox. The data is stored in database.
I want to display the quantity of the selected item of a drop down list... from database into Drop Down List. <% DataSource data = new... = con.prepareStatement("select * from library.booklist"); ResultSet result
jQuery 'select' form event
jQuery 'select' form event In this tutorial, we will discuss about 'select ' form event to display message when we select something inside input box. In this Example, two input text box are given , when we select
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 containing a method which is returning an ArrayList. I want to display the records
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 containing a method which is returning an ArrayList. I want to display the records
Dynamic retrieval od data from database and display it in the table at jsp
Dynamic retrieval od data from database and display it in the table at jsp ...; Here is a jsp code that retrieves the data from the database and display...:3306/test", "root", "root"); String query = "select * from employee"; Statement
how to display the data from excel to webpage
how to display the data from excel to webpage  Hi, I need help on following I have a webpage contains a text box and a button(get), i give a value... search for the value 4024 in a excel file and to display the remaining values
how to display data in List Or grid or in table in Jsp
how to display data in List Or grid or in table in Jsp   <%@page... String P Value in List GIrd or Table please help am able to Print display data In out.print.ln on console But i need to display in List
How to display data from database in a TableView
How to display data from database in a TableView  I need to populate a TableView (JavaFx) with database items. I designed the TableView in JavaFx... = hibernateTransaction.hibernateQuerry().list().iterator(); while (ite.hasNext
Program to read the text from a file and display it on a JFrame.
Program to read the text from a file and display it on a JFrame.  import javax.swing.*; import java.io.*; import java.lang.*; import java.awt.*; class MegaViewer1 extends JFrame { JTabbedPane jtp1=new JTabbedPane
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 contentType = request.getContentType(); if((contentType != null)&&
how to display data from jsp file into database
how to display data from jsp file into database  this is a jsp file . look at the line with code-> Statement st=con.createStatement(); in the below example. the error is "cannot convert from java.sql.Statement
SEARCHING THE DATA FROM DATABASE AND DISPLAY THE SEARCHED DATA IN HTML PAGE
SEARCHING THE DATA FROM DATABASE AND DISPLAY THE SEARCHED DATA IN HTML PAGE  pls help me....in this i want to search books from the database... the user specified $data = mysql_query("SELECT * FROM book WHERE upper($field
how to display?
how to display?  How to write a select query for displaying data where i have author as multivalued attribute

Ads