473,511 Members | 14,975 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 2200
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
20310
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...
30
3092
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...
3
1496
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...
7
2151
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
1962
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...
52
9916
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...
2
3218
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...
3
2109
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...
1
1605
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...
0
7252
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,...
0
7153
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...
0
7371
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,...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5077
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...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
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...
0
1583
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 ...

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.