SunQuest
 
       Code Examples
  Home arrow Code Examples arrow Page 5 - Searching Body Text with textRange, part 1...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM developerWorks
 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? 
CODE EXAMPLES

Searching Body Text with textRange, part 1: The Basic Script
By: Dan Wellman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 17
    2005-06-23

    Table of Contents:
  • Searching Body Text with textRange, part 1: The Basic Script
  • Main Script Variants
  • Some Material to Search
  • Coding the Script File
  • How it Works

  • 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Searching Body Text with textRange, part 1: The Basic Script - How it Works


    (Page 5 of 5 )

    The functionality of the page is simple. It has a script containing two functions; one function is mapped to the ok button and one to the cancel button. The ok function gives an alert if the input field is left blank, but providing a value has been entered, it passes this back to the element that called it in the first place, which as we know is the searchWord variable in the behavior file. The cancel function simply returns nothing and closes the dialog window. 

    Save this as searchwindow.htm in the same location as the other two files. Opening the findingtext.htm file, the text search can now be carried out. I think you'll agree, however, that there are several problems with the dialog box used to enter search terms. Primarily, the problem is that it doesn't look very good -- there are things on it that look bad and are not needed, like the status bar and the help button.  You can tidy this up a little by including the following attributes in the showModalDialog method in the behaviour file:

    status:no;help:no

    Simply append this to the end of the bracketed code. This will improve the look of the search window slightly and remove elements that have no function or use. Using the search button on the initial Web page will now call a window that looks and behaves like a dialog and can be used to find a specific word in the block of text that makes up the body of the document. 

    There is a problem with this however; when the dialog window is open, if the ok button is clicked and there is nothing in the search input, an alert informs the user of this. But when the cancel button is clicked, the dialog simply closes and nothing is returned to the searchWord variable. When this happens, an error occurs, as there is nothing in the script to specify what should happen if this occurs. This is an important part of the errata issues we will look at in the next article; you have to build into your script every attempt to catch any errors that may occur as a result of improper use of your Web page. Add the following if statement directly below the searchWord declaration in the main script file:

    if (searchWord=="") {

          return false

      }

    Now the script knows what to do when an empty string is returned.

    There are also limitations to the functionality of this script; primarily, there is nothing to take into account that there may be more than one occurrence of whatever word the visitor is searching for. Part two of this article goes on to explain how this functionality can easily be added, and goes on to discuss errata in more detail. The promised VBScript version also forms part of this article.


    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.

       · Why should I re-implement the "Find (on this page)" functionality that is provided...
       · Hi,That's a very valid point, however, I'm sure there are many people that are...
       · Sorry, can I also point out that many sites now feature an on-the-page text size...
     

    CODE EXAMPLES ARTICLES

    - Handling Animations and Bitmaps Using GDI+ f...
    - Download a Web Page using the WebClient
    - Creating a Chart using Data from a Database ...
    - The Basics of Charting with the MS Chart Con...
    - Searching Body Text with textRange: Enter th...
    - Searching Body Text with textRange: Building...
    - Searching Body Text with textRange, part 1: ...
    - First Steps in Programming
    - Programming in C
    - Quick Introduction to ASF,ASX, and Networkin...
    - SatView: Pointer Perfect, Part 2: Constructi...
    - SatView: Pointer Perfect, Part 1
    - Style Case Studies: Construction Unions
    - Creating an Engine for Games for Windows
    - Style Case Studies: Generic Callbacks




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway