• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

two dropdown menus

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have two dropdown menus ..upon selecting item from one listbox,items in second listbox shoud change accordingly..
i tried with javascript function event..onChange...but could not able to pass the parameter to querystring..getting error like..Object does not support this property/method..
here goes my code...
<html>
<head>
<title>User page</title>
<script language="JavaScript">

function Selec()
{

var some = (document.user.company.options[document.user.company.selectedIndex].value);
alert(some)
document.user.action = ("UserProcess.jsp?whatstr="+some+"");

document.user.submit();

}

</script>
</head>
<body bgcolor="#123456" text="silver">
<form name ="user" method="post" action="UserProcess.jsp">
<br><br>
<center><h2>User Details</h2></center>
<center><table border="3" bgcolor="gray" bordercolor="silver">
<tr><td>Userid:</td><td><input type ="text" name ="uid"></td></tr>
<tr><td>Password:</td><td><input type ="password" name ="pwd"></td></tr>
<tr><td>Role</td><td><input type ="text" name ="role"></td></tr>
<tr><td>First Name:</td><td><input type ="text" name ="fname"></td></tr>
<tr><td>Last Name:</td><td><input type ="text" name ="lname"></td></tr>
<tr><td>E-Mail:</td><td><input type ="text" name ="email"></td></tr>
<tr><td> Company</td><td> <select name="company" onChange="Selec()">
<%@ page errorPage = "errorpage.jsp" %>
<%@ page language="java" import="java.sql.*" %>
<%!
Connection con = null;
Statement st = null;
ResultSet rs = null ;
String param = null;
%>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc dbc:rannhill","","");
st = con.createStatement();
// database parameters
// generate query
String Query = "SELECT DISTINCT companygroup FROM projects_table";
// get result
rs = st.executeQuery(Query);
// get and display each record
while(rs.next())
{
String comp = rs.getString("companygroup");
%>
<option value= '<%= comp %>'> <%= comp %>

<%
}
// close connections
rs.close();
st.close();
con.close();
%>
</select>
</td>
</tr>

<tr>
<td><b>  Project  </b></td>
<td>
n <select name="project">
<%
Connection con1 = null;
Statement st1 = null;
ResultSet rs1 = null ;

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con1 = DriverManager.getConnection("jdbc dbc:rannhill","","");
st1 = con1.createStatement();
// database parameters
// generate query
param = request.getParameter("whatstr");
System.out.println("this is parameterfrom js function.."+param);
String Query1 = "SELECT DISTINCT title FROM projects_table where companygroup='"+param+"'";
// get result
rs1 = st1.executeQuery(Query1);
System.out.println("after query of projects");
System.out.println(rs1);
// get and display each record
while(rs1.next())
{
String proj = rs1.getString("title");
out.println("<option>" + proj);
}
// close connections
rs1.close();
st1.close();
con1.close();
%>
</select>
</td></tr>
</table>

<br><br>
<center><table width ="200" border="2"><tr>
<td><input type ="submit" value = "Add" name = "action"></td>
<td><input type ="submit" value = "ShowAll" name="action"></td>
<td><input type ="submit" value = "Edit" name="action"></td>
<td><input type ="submit" value= "Delete" name="action"></td>
<td><input type = "Reset" value="Clear"></td></tr></table></center>
</form>
</body>
</html>
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"devender"
Your name doesn't follow the javaranch guidelines. Please take a moment and modify your "Publicly Displayed Name" by editing your profile, after reviewing the guidelines at http://www.javaranch.com/name.jsp
thanks for your cooperation.
- satya
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Devender,
just beginning, with a similar problem, i mixed your code with mine and out came (with the little defect that the first menu doesn't keep the selection, jumps back to default) :
just change connection and insert the lacking table-columns,
if someone has an idea about the remaining defect, i would be glad to read about !
<%@ page import="java.sql.*" %>
<%@ page errorPage="errorpage.jsp" contentType="text/html" %>
<html>
<head>
<script type="text/javascript">
function select()
{
document.user_1.submit();
}
</script>
</head>
<body bgcolor="#FFFFFF">
<h5>Branch</h5>
<form name="user_1" method="post">
<center>
<select name="company" onchange="select()">
<%
DriverManager.registerDriver
(new oracle.jdbc.driver.OracleDriver());
Connection con1 = DriverManager.getConnection
("jdbc racle:thin:@alois:1521 emrep2",
"repos_manager", "admin"
);
Statement stmt1 = con1.createStatement();
ResultSet rs1 = stmt1.executeQuery
("select distinct companygroup from projects_table");
%>
<% while (rs1.next()) { %>
<option value="<%=rs1.getString(1) %>">
<%=rs1.getString(1) %>
</option>
<% } %>
<option value="-1">ALLE</option>
</select>
</center>
<%
rs1.close();
stmt1.close();
con1.close();
%>
</form>
<h5>Project</h5>
<form name="user_2" method="post" action="UserProcess.jsp">
<center>
<select name="project">
<%
String companygroup = request.getParameter("company");
String sql = "select title " +
"from projects_table";
if
(
!(companygroup == null || companygroup.equals("-1"))
)
{
sql = sql + " where companygroup='"+companygroup+"'";
}
DriverManager.registerDriver
(new oracle.jdbc.driver.OracleDriver());
Connection con2 = DriverManager.getConnection
("jdbc racle:thin:@alois:1521 emrep2",
"repos_manager", "admin"
);
Statement stmt2 = con2.createStatement();
ResultSet rs2 = stmt2.executeQuery(sql);
%>
<% while (rs2.next()) { %>
<option value="<%=rs2.getString(1) %>">
<%=rs2.getString(1) %>
</option>
<% } %>
<option value="-1">ALLE</option>
</select>
</center>
<hr>
<center>
<input type="submit" value="Show">
</center>
<%
rs2.close();
stmt2.close();
con2.close();
%>
</form>
</body>
</html>
[ October 28, 2002: Message edited by: Code Seeker ]
[ October 28, 2002: Message edited by: Code Seeker ]
 
Do not set lab on fire. Or this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!