473,671 Members | 2,511 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access Data from Database By Submitting The Combo Box Values

11 New Member
i am making a program in a JSP. i have used some java script code in this program.

by this program i can find out the result for between years for any class.
i have three combo box for class_name, from_year, to_year. for class_name, Its value is 1 to 12. when i select class 11 or 12, an combox appear for subject having values Arts, comerce and science will be appeared.

in database for class 1 to 10 having subject values is AllSubject. and for class 11 or 12 having subject values arts, commerce and science.

my problem how i make the query which send for class 1 to 10 , assume subject values is all and for class 11 or 12 subject values arts, commerce and science with others combox values.

Here is JSP's files:

display.jsp:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <body>
  4. <form name="form" >
  5. <table align="center">
  6.  
  7. <script language="javascript">
  8. function sendData(){
  9. var sch=document.form.school.value;
  10. var cla=document.form.class_name.value;
  11. var y1=document.form.from_year.value;
  12. var y2=document.form.to_year.value;
  13. window.open("show.jsp?class_name="+cla+"&&from_year="+y1+"&&to_year="+y2+"&&school="+sch);
  14. alert(sch+" "+cla+ " "+y1+" "+y2);
  15. }
  16.  
  17. function hide(){
  18. if (document.getElementById){
  19. document.getElementById('combo').style.visibility = 'hidden';
  20. }
  21. }
  22. function call(class_name){
  23. var val = class_name.options[class_name.selectedIndex].text;
  24. if((val=='11')||(val=='12')){
  25. document.getElementById('combo').style.visibility = 'visible';
  26. var arr = new Array();
  27. arr[11] = new Array("Art","Commerce","Science");
  28. arr[12] = new Array("Art","Commerce","Science");
  29. var comboValue = class_name.value;
  30. document.forms["form"].elements["combo2"].options.length=0;
  31. for (var i=0;i<arr[comboValue].length;i++)
  32. {
  33. var option = document.createElement("option");
  34. option.setAttribute('value',i+1);
  35. option.innerHTML = arr[comboValue][i];
  36. document.forms["form"].elements["combo2"].appendChild(option);
  37. }
  38. }
  39. else{
  40. document.getElementById('combo').style.visibility = 'hidden';
  41. }
  42. }
  43. </script>
  44. <body onload="hide();">
  45. <p></p><br><br><br><br><br><br>
  46. <tr><td style="width: 11px"> <span>Class</td> <td><select name="class_name" onchange="call(this); >
  47. <%
  48.  
  49. for( int i=1;i<=12;i++){
  50. %>
  51. <option value="<%=i%>"><%=i%></option>
  52. <%
  53. }
  54. %>
  55. </select><td>
  56. <select id="combo" name="combo2">
  57. </select></td>
  58.  
  59. <tr><td style="width: 11px"> <span>From Year</td><td><select name="from_year">
  60. <%
  61. for(int j=2000;j<=2010;j++){
  62. %>
  63. <option value="<%=j%>"><%=j%></option>
  64. <%
  65. }
  66. %>
  67. </select></td></tr>
  68. <tr><td style="width: 11px"> <span>To Year</td><td><select name="to_year">
  69. <%
  70. for(int k=2000;k<=2010;k++){
  71. %>
  72. <option value="<%=k%>"><%=k%></option>
  73. <% } %>
  74. </select></td></tr><td></td>
  75. <tr><td style="width: 11px"> <span><input type="button" value="Result" onclick="sendData();"></td></tr>
  76. <tr><td><input type="hidden" name="school" value="<%=request.getParameter("school")%>"></td></tr>
  77. </table>
  78. </form>
  79. </body>
  80. </head>
  81. </html>
  82.  
show.jsp:
Expand|Select|Wrap|Line Numbers
  1. <%@ page language="java" import="java.lang.*" import="java.sql.*" import="java.io.*" import="java.net.*"%>
  2. <html>
  3. <body>
  4. <%
  5. String school=request.getParameter("school");
  6. String class_name=(String)request.getParameter("class_name");
  7. String from_year=(String)request.getParameter("from_year");
  8. String to_year=(String)request.getParameter("to_year");
  9. %>
  10. <table align="center" border="1" align="center">
  11. <br>
  12. <tr align="center">
  13. <td width="150"height="30"><font size="+1">Year</td></font>
  14. <td width="150"height="30"><font size="+1">Class</td></font>
  15. <td width="150"height="30"><font size="+1">Subject</td></font>
  16. <td width="150"height="30"><font size="+1">Total Students</td></font>
  17. <td width="150"height="30"><font size="+1">Passout Students</td></font>
  18. <td width="150"height="30"><font size="+1">Marks Obtained 60 To 80</td></font>
  19. <td width="150"height="30"><font size="+1">Marks Obtained over 80</td></font>
  20. <td width="150"height="30"><font size="+1">Overall Result</td></font>
  21. <td width="150"height="30"><font size="+1">School</td></font>
  22. </tr>
  23.  
  24. <%
  25. Connection con = null;
  26. try {
  27. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
  28. con = DriverManager.getConnection("jdbc:odbc:sql;user=sa;password=1234");
  29. System.out.println("Connection created");
  30. Statement st=con.createStatement();
  31. System.out.println("st going to execute");
  32. String query="SELECT * FROM Result WHERE year BETWEEN '"+from_year+"' AND '"+to_year+"' and school='"+school+"'";
  33. System.out.println("now data are selecting");
  34. ResultSet rs=st.executeQuery(query);
  35. System.out.println("now data in rs.....");
  36. System.out.println("now going to rs block............");
  37. while(rs.next())
  38. {
  39. %>
  40. <tr align="center">
  41. <td width="150"height="30"><%out.println(rs.getString(1));%>
  42. <td width="150"height="30"><%out.println(rs.getString(2));%>
  43. <td width="150"height="30"><%out.println(rs.getString(3));%>
  44. <td width="150"height="30"><%out.println(rs.getString(4));%>
  45. <td width="150"height="30"><%out.println(rs.getString(5));%>
  46. <td width="150"height="30"><%out.println(rs.getString(6));%>
  47. <td width="150"height="30"><%out.println(rs.getString(7));%>
  48. <td width="150"height="30"><%out.println(rs.getInt(8));%>
  49. <td width="150"height="30"><%out.println(rs.getString(9));%>
  50. </tr>
  51. <%
  52. }
  53. rs.close();
  54. con.close();
  55. }catch(Exception e){out.println(e);}
  56. %>
  57. </table>
  58. </body>
  59. </html>
  60.  
combox box for subject remain hide when i select class 1 to 10. but if i select class 11 or 12 then
value for subject is Arts, Commerce and Science. how i make query from database base on the subject.

please help.
Apr 11 '10 #1
3 2205
acoder
16,027 Recognized Expert Moderator MVP
Unless you need the user to select one of the three schools/subjects, you can do this on the server-side rather than using JavaScript.
Apr 29 '10 #2
vijaykumardahiya
11 New Member
@acoder
thanks for reply, It will be appreciable if you will do some more focus.
Apr 29 '10 #3
acoder
16,027 Recognized Expert Moderator MVP
It is quite difficult to follow exactly what you're after.

Could you explain what the following means:
my problem how i make the query which send for class 1 to 10 , assume subject values is all and for class 11 or 12 subject values arts, commerce and science with others combox values.
If you need to formulate a query, that is in your JSP code, not JavaScript.
Apr 30 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
20343
by: Vladimir | last post by:
Hello, I have a table in MS Access database. It has one field (with BYTE datatype) that has several properties set in Lookup tab of table Design View. Display Control = Combo Box. Row Source Type = Value List. Row Source = "1; "Above"; 2; "Below"; 3; "Equal"". When I try to SELECT <field> FROM <table> in my C++ application through ADO, I get numeric value of the field. How can I get string representation of this numeric value from the...
30
3116
by: Andante.in.Blue | last post by:
I just browsed through some of my Access links when I came across the Ten Commandments of Access (http://www.mvps.org/access/tencommandments.htm). Some of the points I heartily agree with (and wish that my predecessor had followed) but -- alas -- being a relative beginner to Access, I can't see the reasoning behind one of the points and the site does not provide any rationale / explanation for its presence either: 2. Thou shalt never...
3
1511
by: Pasquale | last post by:
I have a database used for contact information and another for event information. As part of the event database, we would like to keep record of the people that are attending a certain event. These are the same people who are in the contact database. Using a MS Access form in the event database, is there a way to select the names from the contact database in the Name field when adding who is attending an event, rather than typing their...
7
2159
by: Ruben Baumann | last post by:
Just wondered if anyone has had occasion to use, or does use, FileMaker, or Raining Data's Omnis, or Alpha5's software, and how they compare with Access? Ruben
1
1969
by: Johnny | last post by:
Hello, I've read somewhere that you can validate form data before actually submitting it, similar to what validation controls would do. For example, I have a form that has 2 textboxes. I populate the 2 textboxes with values from the database. I also have an update button that will update the values. If I have not made any change to the data in the textboxes, then I do not want to submit the data when the update button is clicked. I...
52
9957
by: Neil | last post by:
We are running an Access 2000 MDB with a SQL 7 back end. Our network guy is upgrading to Windows Server 2003 and wants to upgrade Office and SQL Server at the same time. We're moving to SQL Server 2005, and, since he already has licenses for Office Pro 2002, he wants to upgrade to that. I've been saying that we need to upgrade to Access 2003, not 2002, even if Office is kept at 2002. We are also looking to do a fair amount of...
2
3223
by: Michael Bialowas | last post by:
Hello all, I have been searching the net endlessly and found this ng, so I thought I would give a try. Anyways, I have a few problems I am trying to implement a combo box which presently contains the following: Description, Price, and Treatment code. I wish to do the following: when the description field(combo box) is clicked I want the price, treatment code, insured field to become automated(update the corresponding data automatically)....
3
2117
by: Brian Graham | last post by:
I have a combo box with a query for a list of names etc. The table has 250,000 rows. The query returns 250,000 rows. But the list returns only 97,000 rows and then shows blank columns after that, so it appears to be returning 250,000 rows but most of them incomplete. So, I have names from A to D but nothing after that. The table was initially an SQL rdbms table but I've imported the data directly into Access with no change in results. BTW, I...
1
1612
by: asp beginner | last post by:
I am building an Eccomerce site and I am trying to make my shopping cart work. I am having a problem with when I have entered data into my form it is not submitting into my access database. This my coding for my page. I am very new at all this and any help with be most appreciated. <%@ Page Language="vb" Debug="True"%> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %> <%@ Import Namespace="System.Drawing" %>...
0
8483
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8401
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8603
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6236
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4416
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2818
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2060
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.