473,763 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to sort the table using combo box values

10 New Member
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.sq l.*"%>
<html>
<head>
<title>Add a new Address</title>


<script type="text/javascript">

function sort()
{
var k=document.getE lementById("myl ist").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;
PreparedStateme nt stmt = null;
try {
Class c = Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
}
catch (Exception e) {
System.out.prin tln("Error occurred " + e);
}
try {
conn = DriverManager.g etConnection("j dbc:odbc:data") ;

}
catch (Exception e) {
System.out.prin tln("Error occurred " + e);
}
try {
stmt = conn.prepareSta tement("INSERT INTO address(name, street, city, country, telephone) VALUES (?, ?, ?, ?, ?)");
stmt.setString( 1, request.getPara meter("name"));
stmt.setString( 2, request.getPara meter("street") );
stmt.setString( 3, request.getPara meter("city"));

stmt.setString( 4, request.getPara meter("country" ));
stmt.setString( 5, request.getPara meter("tel"));
stmt.executeUpd ate();
stmt.close();
conn.close();
}
catch (Exception e) {
System.out.prin tln("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">ci ty</option>
<option value="country" >country</option>
<option value="telephon e">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.getPa rameter("k");%>
<%@ page import = "java.sql.* "%>
<html>
<body>
<%
Connection connection = DriverManager.g etConnection(
"jdbc:odbc:data ", "", "");

Statement statement = connection.crea teStatement();

String name=request.ge tParameter("nam e");
String street=request. getParameter("s treet");
String city=request.ge tParameter("cit y");
String country=request .getParameter(" country");
String telephone=reque st.getParameter ("telephone" );
ResultSet rs=statement.ex ecuteQuery("sel ect * from address order by '"+s+"'");

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

<TH>Name</TH>
<TH>Street</TH><TH>City</TH><TH>Country</TH><TH>TelePhon e</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.prin tln(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 5972
r035198x
13,262 MVP
1.)Please use code tags everytime when posting code.
function sort()
{
var k=document.getE lementById("myl ist").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
Nirmala123
10 New Member
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.ex ecuteQuery("sel ect * from address order by '"+s+"'");

Thanks in Advance.
Jul 6 '07 #3
r035198x
13,262 MVP
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.ex ecuteQuery("sel ect * 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 New Member
Hi,

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

String k =request.getPar ameter("k");
Jul 6 '07 #5
Nirmala123
10 New Member
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
2611
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 that report - sorted first on (ascending) then on (ascending). Of course, there are more supporting fields in the table. The above 3 are the significant fields for this discussion.
2
3879
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 believe I am adding a form-level validation. Is it wise to also include the table-level validation for the above constraint? For instance, go to the field's validation rule property in Design Mode and
3
10376
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 problem though. I'm looking to be able to sort multiple fields from a form whose record source is a query of fields from a single table. Background: The default view is "Continuous Forms." and in the Form Header section of the form's design, I...
1
1711
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
3365
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. As part of the setup, I specified a new dataset, which included the data & lookup tables. I also specified the relationships when required. I then added a combo box control to my form, following the instructions from
7
3342
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 LastName, "x" As FirstName From qryStudents UNION SELECT StudentID, FullName, LastName, FirstName FROM qryStudents ORDER BY LastName;
0
1995
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 values of prefixes from the Prefix table based on the PrefixID in the Prefix table. When I load a windows application form, I can display and update data from the primary table. This includes the prefixID value. If I display a combo box with...
6
2450
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
6559
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 Table/Query Row Source SELECT .LastName, .FirstName, .EmployeeNumber FROM ; Bound Column 3 Column Count 3 Column Heads Yes Column Widths 1";1";1"
0
9566
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
10149
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...
0
10003
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9943
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,...
0
9828
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8825
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7370
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...
1
3918
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
3529
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.