Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How to use DHTML to add wildcard characters to a database query in FrontPage 2003


View products that this article applies to.

For a Microsoft FrontPage 2000 version of this article, see 317924.
For a Microsoft FrontPage 2002 version of this article, see 318435.

↑ Back to the top


Summary

Use this step-by-step guide to add wildcard characters to a database search form by using Dynamic HTML (DHTML). The example in this article uses a <Like> query and DHTML to create a better version of the built-in <Contains> query.

Note This article uses custom DHTML that may not be available in all browsers. For more information about compatibility with other browsers, click Microsoft FrontPage Help on the Help menu, type compatibility in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

Note You may receive an error message if you copy the examples directly from this article and paste them into FrontPage. The angle brackets (< and >) may appear as escaped HTML code (< and >). To work around this behavior, paste the script into a blank Notepad document, and then copy it from Notepad before you paste it into FrontPage.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs.
If you have limited programming experience, you may want to contact a Microsoft Certified Partner or Microsoft Advisory Services. For more information, visit these Microsoft Web sites:

Microsoft Certified Partners - https://partner.microsoft.com/global/30000104

Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site: http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

↑ Back to the top


More information

Step 1 - Prepare to Use the ASP Features in FrontPage

Before you can use the ASP features in FrontPage 2003, install the components that are listed in the following Microsoft Knowledge Base article:
318287 FP2002: What You Need to Use Active Server Pages (ASP) in FrontPage 2002

Step 2 - Create a Database Results Page

  1. In FrontPage 2003, open a Web site on a Web server that supports Microsoft Active Server Pages (ASP).
  2. On the Standard toolbar, click the New Page button.
  3. Create a Database Results Region.

    To do this, point to Database on the Insert menu, and then click Results.
  4. Click Use a sample database connection (Northwind), and then click Next.
  5. For record source, click the Products table, and then click Next.
  6. Click More Options.
  7. Click Criteria.
  8. Click Add.
  9. In the Add Criteria dialog box, set the following options:
    • Set the field name to ProductName.
    • Set the comparison to Like.
    • Use the default, ProductName, for the value.
    • Click to select the Use this search form field check box if you have to.
  10. Click OK to close the Add Criteria dialog box.
  11. Click OK to close the Criteria dialog box.
  12. Click OK to close the More Options dialog box.
  13. Click Next.
  14. Click Next.
  15. Click Finish.
  16. Save the page to your Web and name it ProductName.asp.

Step 3 - Add DHTML to the Page

  1. Switch to HTML view.
  2. Add the following DHTML code before the closing
    </head>
    tag:
    		<script language="javascript">
    		function FixMe(tmpForm,tmpField)
    		{
    		  var strTemp = tmpField.value.toString();
    		  if (strTemp.substring(0,1) != '%')
    		    strTemp = '%' + strTemp;
    		  if (strTemp.substring(strTemp.length-1,strTemp.length) != '%')
    		    strTemp = strTemp + '%';
    		  tmpField.value = strTemp;
    		  tmpForm.submit();
    		}
    		</script>
  3. Locate and delete the following code:
    <form BOTID="0" METHOD="POST" ACTION="productname.asp">
    and replace it with this code:
    <form BOTID="0" METHOD="POST" ACTION="productname.asp" onSubmit="FixMe(this,this.ProductName)">
  4. Switch back to normal view.
  5. Save the page to your Web.

Step 4 - Test the Page

  1. On the Standard toolbar, click the Preview in Browser button.

    No form fields should appear on the page.
  2. Do not type any text.

    Click Submit. The search form field should contain a single percent sign (%) and all the records are returned.
  3. Clear the input field on the search form, type Bob's, and then click Submit.

    %Bob's% appears in the input field and all the fields that contain that text string are displayed.

↑ Back to the top


References

For additional information about errors that can appear when working with the Database Results Region, click the following article numbers to view the articles in the Microsoft Knowledge Base:
265320 Fs000: Error Message When You Query the Database
299911 FP2002: Error Message Appears in Database Results Region When You Preview a Page
287147 FP: Error Message: "Database Results Error" When You Update a Database Record
317931 FP: Error 0x80040E14 When Using a Database 'Contains' Query

↑ Back to the top


Keywords: KB825519, kbhowto, kbdatabase, kbquery

↑ Back to the top

Article Info
Article ID : 825519
Revision : 10
Created on : 12/18/2006
Published on : 12/18/2006
Exists online : False
Views : 363