HTML
  Home arrow HTML arrow Page 4 - Using the Find Functions for HTML Database...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
HTML

Using the Find Functions for HTML Database Forms
By: Chrysanthus Forcha
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-08-20

    Table of Contents:
  • Using the Find Functions for HTML Database Forms
  • The ordinarySearch() function
  • The getTwoWords() Function
  • The find() Function

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using the Find Functions for HTML Database Forms - The find() Function


    (Page 4 of 4 )

    The find() function uses all the above functions to do its work. I will give you the function first before I explain how it operates.


    function find()

    {

    var titleAndItem = prompt("Enter the Title and Item separated by one Space (example shown)", "Name Smith");

     

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

    {

    //validate Find form entry

    var arr = getTwoWords(titleAndItem);

    if (arr[1] == "")

    alert('You did not type correctly.')

    else

    {//call the appropriate search function.

    // first check if the column for the title is sorted.

    var titleInx = getColumnIndex(arr[0]); //the cell index of the recordset

    if (titleInx == 6)

    alert('You did not type the title correctly.') //title does not exist

    else

    {//title exist

    var foundRowIndex;

    if (titleBoolArr[i][1] == "true")

    foundRowIndex = binarySearch(arr[1], titleInx);

    else

    foundRowIndex = ordinarySearch(arr[1], titleInx);

     

    //if foundRowIndex is total number of rows then item was not found

    if (foundRowIndex == numberOfRows)

    alert('Item was not found')

    else

    {//item was found - so display the items on the form controls

    if (foundRowIndex == 0) //the first row was seen

    showFirstRow();

    else if (foundRowIndex == (numberOfRows - 1)) //the last row was seen

    showLastRow();

    else

    {//a row between the first and the last was seen

    index = foundRowIndex; //the new index

    for (j=0;j<6;j++)

    {

    //form the input text control ID

    CID = "EI" + j;

    //form the recordset ID

    RID = "TD" + index + j;


    document.getElementById(CID).value = document.getElementById(RID).innerHTML;

     

    //show the data row number

    document.getElementById('RowPosition').value = index + 1;

    }

    //enable all navigation buttons

    enableButtons('SFA1','SP1','SN1','SL1');

    }

    }

    }

    }

    }

    }


     

    When the Find button on the form is clinked, the JavaScript find() function is called. The first thing it does is issue a prompt dialog box. I have explained above what the dialog box takes as input. The line for the code is:


    var titleAndItem = prompt("Enter the Title and Item separated by one Space (example shown)", "Name Smith");


    The first argument for the prompt function is an instruction to the user on what he has to do. The second is the default value that goes into the input text control. In this case it serves as an example of what the user should type. The prompt() function returns a string made up of the title of a column and a cell value of the column. The returned string is held by the variable, titleAndItem.

    The find() function only continues if titleAndItem is not null and is not an empty string. When it continues, it first of all validates the string (titleAndItem) returned by the prompt() function. Well, it does not do a lot, it simply checks to see if the titleAndItem is made up of two words. If it isn't, the error message "You did not type correctly" is issued. Otherwise the find() function uses the two words. The cell value is called the key.

    The find() function then goes on to get the column index for the title by calling the getColumnIndex() function. This function takes the title of the column as an argument. If it sees the index, it returns it, which is a number between 0 and 5. If it returns 6, the total number of visible columns, it means the index was not found. In this case the find() function issues the error massage "You did not type the title correctly."

    It then goes on to check whether the column for the title is sorted. If the column is sorted, it calls the binarySearch() function, passing the cell value (key) as the first argument and passing the column index as the second argument. If the column is not sorted, it calls the ordinarySearch() function, passing the same arguments as for the binary search. If either of the functions called returns the maximum number of rows in the recordset, it means that the key was not found. In this case the function issues the error message "Item was not found."

    If the item was found, that is the index returned is in the range from 0 to (numberOfRows - 1), the find function has three final options:

    • If the index is the first, that is, 0, the showFirstRow() function is called to display the first record. 
    • If the index is the last, that is, (numberOfRows - 1), the showLastRow() function is called to display the last row.
    • If the index is between the first and last, the function displays the corresponding record and enables all the navigation buttons.

    We shall continue in the next part of the series.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Let's continue with this part of the series.Chrys
     

    HTML ARTICLES

    - Comparing Browser Response to Active Client ...
    - Testing Browser Response to Active Client Pa...
    - Active Client Pages: Completing the Code for...
    - ACP and Browsers: Setting up an Example
    - How Browsers Respond to Active Client Pages
    - Completing a Tree with Active Client Pages
    - HTML Form Verification and ACP
    - Building an ACP Tree
    - Completing an ACP 3D HTML Table Image Gallery
    - Building an ACP 3D HTML Table Image Gallery
    - A Multiple Page Image Gallery with Active Cl...
    - Building an Image Gallery with Active Client...
    - Concluding a Menu for All Browsers
    - A Vertical Menu for All Browsers
    - Downloading Long HTML Pages with ACP







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    Stay green...Green IT