472,983 Members | 2,247 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,983 software developers and data experts.

how to sort the table using combo box values

hi...

I want to sort the table using combobox values. I give the code here.

address.html:

<html>
<head>
<title>Add a new entry</title>
</head>
<body>
<h1>Please enter the new address information</h1>
<form method="POST" action="datajsp.jsp">
Name: <input type="text" name="name" size="20"><br>
Street: <input type="text" name="street" size="20"><br>
City: <input type="text" name="city" size="20"><br>

Country: <input type="text" name="country" size="20"><br>
Telephone: <input type="text" name="tel" size="20">
<p><input type="submit" value="Submit"></p>
</form>
</body>
</html>


datajsp.jsp:


<%@page import="java.sql.*"%>
<html>
<head>
<title>Add a new Address</title>


<script type="text/javascript">

function sort()
{
var k=document.getElementById("mylist").value;
alert(k);
}
</script>



</head>
<body>
<form name=f1 action="http://localhost:8080/examples/datadisplay.jsp">
<h1>New Address Creation using executeUpdate()</h1>
<%
Connection conn = null;
PreparedStatement stmt = null;
try {
Class c = Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (Exception e) {
System.out.println("Error occurred " + e);
}
try {
conn = DriverManager.getConnection("jdbc:odbc:data");

}
catch (Exception e) {
System.out.println("Error occurred " + e);
}
try {
stmt = conn.prepareStatement("INSERT INTO address(name, street, city, country, telephone) VALUES (?, ?, ?, ?, ?)");
stmt.setString(1, request.getParameter("name"));
stmt.setString(2, request.getParameter("street"));
stmt.setString(3, request.getParameter("city"));

stmt.setString(4, request.getParameter("country"));
stmt.setString(5, request.getParameter("tel"));
stmt.executeUpdate();
stmt.close();
conn.close();
}
catch (Exception e) {
System.out.println("Error occurred " + e);
}
finally {
try {
if (stmt != null)
stmt.close();
} catch (Exception e) {}
try {
if (conn != null)
conn.close();
} catch (Exception e) {}
}

%>
The new address has been created.
<br><br>


<select id="mylist">
<option value="name" >name</option>
<option value="street">street</option>
<option value="city">city</option>
<option value="country">country</option>
<option value="telephone">telephone</option></select>
<br><br><font style="margin-left:100px; "></font>
<input type="submit" value="display" onClick="sort();">
</form>
</body>
</html>

datadisplay.jsp:



<%String s="";
s=request.getParameter("k");%>
<%@ page import = "java.sql.*"%>
<html>
<body>
<%
Connection connection = DriverManager.getConnection(
"jdbc:odbc:data", "", "");

Statement statement = connection.createStatement();

String name=request.getParameter("name");
String street=request.getParameter("street");
String city=request.getParameter("city");
String country=request.getParameter("country");
String telephone=request.getParameter("telephone");
ResultSet rs=statement.executeQuery("select * from address order by '"+s+"'");

%>
<TABLE BORDER="1">
<TR>

<TH>Name</TH>
<TH>Street</TH><TH>City</TH><TH>Country</TH><TH>TelePhone</TH>

</TR>
<%
try
{
while(rs.next()){


%>
<TR>
<TD> <%= rs.getString(1) %></td>
<TD> <%= rs.getString(2) %></TD>
<TD> <%= rs.getString(3) %></TD>
<TD> <%= rs.getString(4) %></TD>
<TD> <%= rs.getString(5) %></TD>
</TR>
<% }

}
catch(Exception e)
{
System.out.println(e);
}
%>
</TABLE>
</body>
</html>

In this the table displayed correctly.but i select one value from the combobox and click the display button but it was not the table is sorted.

this is very urgent for me. Please anyone can help me..

Thanks in advance.
Jul 6 '07 #1
5 5928
r035198x
13,262 8TB
1.)Please use code tags everytime when posting code.
function sort()
{
var k=document.getElementById("mylist").value;
alert(k);
}
</script>.
Is this all the sort function that you have? Surely you don't expect that the sort the table.
Jul 6 '07 #2
1.)Please use code tags everytime when posting code.

Is this all the sort function that you have? Surely you don't expect that the sort the table.
Thanks for your reply...

no i want to get that k value in next page. For all the sorting i do in the database query.

so please help me how to get that combobox value(that mean k in sort()) in the query.

ResultSet rs=statement.executeQuery("select * from address order by '"+s+"'");

Thanks in Advance.
Jul 6 '07 #3
r035198x
13,262 8TB
Thanks for your reply...

no i want to get that k value in next page. For all the sorting i do in the database query.

so please help me how to get that combobox value(that mean k in sort()) in the query.

ResultSet rs=statement.executeQuery("select * from address order by '"+s+"'");

Thanks in Advance.
Put the value in a hidden input field on the form that's submitted. Then in the next page you get that value using

Expand|Select|Wrap|Line Numbers
  1. String value = request.getParameter("paramName");
Jul 6 '07 #4
praveen2gupta
201 100+
Hi,

In datadisplay.jsp page you are not getting value of k.So it is not working
Try following code

String k =request.getParameter("k");
Jul 6 '07 #5
Put the value in a hidden input field on the form that's submitted. Then in the next page you get that value using

Expand|Select|Wrap|Line Numbers
  1. String value = request.getParameter("paramName");
Thank you very much. It is working fine.
Jul 6 '07 #6

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

Similar topics

1
by: MLH | last post by:
I have a challenge... In a table I call tblStuff4Letters with 3 fields: , and . I have a report called rptOutboundCorrespondence that feeds off this table. Sorting & grouping is turned on in...
2
by: Kostas | last post by:
Just a quick question on this issue. Assume a small set of fixed values for a field. For instance Field Gender, values: Male, Female, Unknown If I create a Combo Box with the above values, I...
3
by: rquinnan | last post by:
Good Evening all, I would greatly appreciate any assistance on this Access 2003 quandary I'm in. And I do apologize if this has been answered somewhere else, I didn't see one that addressed my...
1
by: Dreamerw7 | last post by:
Hi, I know this is probably a dumb question, but here goes: I have 3 tables: REGION REG_ID REGION
1
by: James | last post by:
I am used to VB6 but need to develop something in .Net. I need to create several bound combo-boxes which will use lookup tables to get their values. I created a form using the dataform wizard....
7
by: Arnold | last post by:
Greetings Gurus, In a mainform's header, I have a combobox named comboStudents. The rowsource for this combobox is: SELECT -999 As StudentID, "<Add New Student>" As FullName, "aaa" As...
0
by: northshore | last post by:
Hello, I am creating a windows application database. I have a primary table 'Individuals' and a lookup table 'Prefixes.' In the Individuals table, I have a column 'PrefixID' that references...
6
by: cygsoft | last post by:
I hava a combobox. in that contain date,subject,sender. How to sort date,sender and subject while using combox in inbox
14
by: Mark | last post by:
I have a table with a field that uses a combobox to populate values. The Lookup tab within table design mode is the following: Display Control Combo Box Row Source Type ...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.