473,395 Members | 1,931 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 5955
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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
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...
0
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...

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.