• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

onChange Event to call a frame.

 
j u ray
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well here is an example of what you need to do (once you understand it, you can change your code appropriately):

 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
j u ray
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic