Home arrow HTML arrow Sorting for Database Forms with HTML

Sorting for Database Forms with HTML

Welcome to the sixth part of a fourteen part series detailing how to create database forms in HTML. In this article, we will discuss sorting and its various functions as well as the boolean values that come as a result. Please join us as we tackle these issues.

Author Info:
By: Chrysanthus Forcha
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
August 13, 2008
  1. · Sorting for Database Forms with HTML
  2. · The sort() Function continued
  3. · The getColumnIndex() Function
  4. · The titleBoolArr Array

print this article

Sorting for Database Forms with HTML
(Page 1 of 4 )

Appreciation of Sorting

When data is retrieved from a database, you can have it sorted by the database engine before you receive it at the client. Sorting, whether done by the database engine at the database server or by the client, is based on one column. That is, one column is sorted alphabetically while the others are not sorted. It can only be this way, since the data exist in rows and a row must always have the same elements. If you exchange the positions of two elements in a column during sorting, you are exchanging their corresponding rows to the same positions as you have done for the elements of the column, otherwise the integrity of each row will not be maintained. So you will hardly see an ascending or descending order in more than one column.

Now, the data may come from the database sorted (based on a column) or not sorted. Even if it is sorted, you may want to see the data in a different order. You can have a function (JavaScript) that will sort the data in ascending or descending order based on any column. For simplicity, I have considered only sorting in ascending order.

The sort() Function

There are different algorithms for sorting an array of strings. Time-critical client applications often use the algorithm called Quicksort, which is very efficient. The application for this article is a time-critical client one, so the function I use is an implementation of the Quicksort algorithm. I wrote an article for www.devarticles.com titled “Quicksort.” In this article, I explain how the Quicksort function operates. You can read the article if you want to know how the function operates. Here, I will simply tell you what you send into the function and what you get out of it.

When the user clicks the Sort button, the following function is called:

function sort()


//display a dialog box that prompts the user for input of title – “Name” is default

var title = prompt("Enter the Title of the Column for Sorting", "Name");

if ((title != null)&&(title != ""))


var titleInx = getColumnIndex(title); //the column index of the recordset

if (titleInx == 6)


alert(‘The title does not exist - type with the right case without abbreviation.');



quickSort("0", (numberOfRows - 1), titleInx);



setTitleBool(title); //indicate in the titleBoolArr array that the column with the title is sorted


blog comments powered by Disqus

- Does HTML5 Need a Main Element?
- Revisiting the HTML5 vs. Native Debate
- HTML5: Not for Phone Apps?
- HTML5 or Native?
- Job Hunting? Freelancer.com Lists This Quart...
- HTML5 in the News
- Report: HTML5 Mobile Performance Lags
- The Top HTML5 Audio Players
- Top HTML5 Video Tutorials
- HTML5: Reasons to Learn and Use It
- More of the Top Tutorials for HTML5 Forms
- MobileAppWizard Releases HTML5 App Builder
- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials