Home arrow HTML arrow Page 2 - Using the Find Functions for HTML Database Forms
HTML

Using the Find Functions for HTML Database Forms


You may have any number of reasons to find a particular recordset in a database. Sometimes finding what you want is easier said than done. This article walks you through the different search functions (also known as Find functions) and shows you when you should use them. This is the seventh part of a thirteen part series that focuses on database forms with HTML.

Author Info:
By: Chrysanthus Forcha
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
August 20, 2008
TABLE OF CONTENTS:
  1. · Using the Find Functions for HTML Database Forms
  2. · The ordinarySearch() function
  3. · The getTwoWords() Function
  4. · The find() Function

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Using the Find Functions for HTML Database Forms - The ordinarySearch() function
(Page 2 of 4 )

When the recordset is not sorted, this function does the searching. It takes as arguments the cell value whose row is searched, and the index of the column having the cell. This cell value is called the key. If it sees the value, it returns the row index. If it doesn't see the value, it returns the total number of rows in the recordset; note that this is one unit higher than the maximum row index. It is up to the calling function to interpret the result. This is the function:


function ordinarySearch(key, titleInx)

{

for (i=0; i<numberOfRows; ++i)

{

if (document.getElementById('Recordset').rows[i].cells[titleInx].innerHTML == key)

return i;

}


return numberOfRows;

}


The binarySearch() function

This function is called when the recordset is sorted. When the recordset is sorted, the search from this function is very fast, much faster than that of the ordinary search. The function takes as arguments the same parameters that the ordinary search takes. It returns the same values under the same conditions. If the user wants to be sure to have a fast search, he can sort the recordset based on the column, which has the cell value he will find. After that he finds the cell value (row) by clicking the Find button. This is the binarySearch() function:


function binarySearch(key, titleInx)

{

var left = 0;

var right = numberOfRows - 1;

 

while (left <= right)

{

var mid = parseInt((left + right)/2);

if (document.getElementById('Recordset').rows[mid].cells[titleInx].innerHTML == key)

return mid;

else if (document.getElementById('Recordset').rows[mid].cells[titleInx].innerHTML < key)

left = mid + 1;

else

right = mid - 1;

}

 

//when element is not found

return numberOfRows;

}


If you want to know how the function operates, consult the article I wrote. The recordset is like a two dimensional array. The binarySearch() function here is slightly different from the one I wrote in the article. In that article, searching is done only for a one-dimensional array. Here the function is different, because the two dimensional array aspects have to be taken into consideration.


blog comments powered by Disqus
HTML ARTICLES

- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5
- BBC Adopts HTML 5, Mozilla Addresses Issues
- Advanced Sticky Footers in HTML and CSS
- HTML and CSS Sticky Footers
- Strategy Analytics Predicts HTML5 Phones to ...
- HTML5 Guidelines for Web Developers
- Learning HTML5 Game Programming
- More Engaging CSS3 and HTML Background Effec...
- Engaging HTML and CSS3 Background Effects
- More Web Columns with CSS3 and HTML
- Columns with CSS3 and HTML
- Creating Inline-Block HTML Elements with CSS
- Drag and Drop in HTML5: Parsing Local Files

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



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