File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes onChange Event to call a frame. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "onChange Event to call a frame." Watch "onChange Event to call a frame." New topic
Author

onChange Event to call a frame.

j u ray
Greenhorn

Joined: Sep 21, 2009
Posts: 9
hello everyone,
i am new to JSP. I am having a drop down combo box names as "fname". When I will select any value from the drop down combo, than in the SAME PAGE only, i want to display same data in table retrieving from database. the database i.e. the table is in MS Access.

I have made the connection and can retrieve data from databse (as i have tried out in different JSP file). but i nedd to display the table in the same page when i will select a data from the combo. for different value selected different data will be displayed after retrieving from table. i cannot use any thing other than this.

i cannot use servlet or SQL, as the specification is like this.

my code is ::-

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<%@ page language="java" %>
<%@ page import ="java.sql.*" %>

<%

try {

String dataSourceName = "prodTest";
String dbURL = "jdbc:odbc:" + dataSourceName;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String sTable = "production_dept";
String sSql = "SELECT FacultyName FROM " + sTable;

Connection cn = null;
Statement st = null;
ResultSet rs = null;

cn = DriverManager.getConnection(dbURL,"","");
st = cn.createStatement();
rs = st.executeQuery( sSql );
ResultSetMetaData rsmd = rs.getMetaData();
int n = rsmd.getColumnCount();
%>

<% String FacultyCombo = null;%>
<select name="fname" id= "fname" tabindex="20" onchange=" ">
<option VALUE=0>Choose Faculty Name</option>;
<%
while(rs.next())
{
FacultyCombo = rs.getString("FacultyName");%>
<option value='<%=FacultyCombo%>'><%out.println(FacultyCombo);%></option>
<% } %>
</select>

<% }

catch (Exception err) {
out.println("ERROR to be shown here: " + err);
}
%>


please reply soon. it is very urgent.
James Ward
Ranch Hand

Joined: Apr 27, 2003
Posts: 263
You can have a 'iframe' in your page, which will display the data based on combo box value selected in the main page.
The iframe can be refreshed with a param, via onChange event of the combo box using javascript.
j u ray
Greenhorn

Joined: Sep 21, 2009
Posts: 9
Hello James,
I am new to JSP. Can you please get me the code for my problem.
Where to declare the 'iframe'. the code is getting connected to the Database, but i am not able to display the data in the same page.

please help me.
James Ward
Ranch Hand

Joined: Apr 27, 2003
Posts: 263
Well here is an example of what you need to do (once you understand it, you can change your code appropriately):

Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

J. U. Ray, please Ease Up and Use Code Tags when you post a source code. Also you are creating JDBC connections in your JSP which is not a good practice. Usually requests go through a servlet before reaching a JSP and that servlet does all the logic and database work...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
j u ray
Greenhorn

Joined: Sep 21, 2009
Posts: 9
James,

if i change the iframe to:

<iframe id="detailsIframe" name="detailsIframe" src="">

then nothing is being passed to "fetchDetails.jsp".

the value which i selected from the drop down list is getting selected, as i have tried to print in the Java script it is getting printed.

but i am unable to pass the value to next page i.e. "fetchDetails.jsp".

let me know how to pass the value to next page and how to use the value for further work because in next page i have to run a query based on this value.

thanks in advance.
James Ward
Ranch Hand

Joined: Apr 27, 2003
Posts: 263
You can change iframe to:


This will present a empty frame.

If you give src ="/fetchDetails.jsp?selection=0", then that Jsp will be invoked and its result presented in the iframe.
I had put it there, in case there is a default result to be displayed.

In fetchDetails.jsp you need to put the code that will display data based on parameter passed to it. The parameter in this case is 'selection=N'.


See the javascript function, it is changing the value of iframe src value, based on combo box selection. When this happens, the iframe refreshes.
j u ray
Greenhorn

Joined: Sep 21, 2009
Posts: 9
Hello James,

if i change the iframe to:

<iframe id="detailsIframe" name="detailsIframe" src="">

then nothing is being passed to "fetchDetails.jsp".

the value which i selected from the drop down list is getting selected, as i have tried to print in the Java script it is getting printed.

but i am unable to pass the value to next page i.e. "fetchDetails.jsp".

let me know how to pass the value to next page and how to use the value for further work because in next page i have to run a query based on this value.

thanks in advance.
 
GeeCON Prague 2014
 
subject: onChange Event to call a frame.