Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


May 28, 2008

Creating Context-Sensitive Help Screens for Your HTAs

Provide Help information in your applications by using JScript to write a pop-up function
RSS
Subscribe to Windows IT Pro | See More Jscript Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

Executive Summary:

You can use JScript to write a pop-up function to provide help information in your HTML Applications (HTAs). To create a context-sensitive Help pop-up, you have to assign each form element an ID attribute. Also, each form element that needs a context-sensitive Help pop-up has both a Case clause and a Help pop-up function.


I always try to include some type of Help feature within each of my HTML Applications (HTAs), and until recently, I was using a very basic approach to display a Help screen within each application. The Help screen was initiated by the onhelp event from within the HTML <BODY> tag (i.e., <BODY onhelp="ShowHelp" >). In this case, ShowHelp referenced a subroutine that would run when the user pressed the F1 key. The ShowHelp subroutine that I wrote used a MsgBox function to display helpful text and instructions for the user. For some applications, I provided basic help information, but for other HTAs I provided much more detailed help text and instructions. Regardless of how much detail I put into it, the help that I provided was limited to the functionality that a message box could provide, which was basically a lot of text with a few Visual Basic (VB) carriage return/line feeds thrown in to make it look a little better. Furthermore, I could provide only one Help screen for the entire application. This method worked fairly well for most applications, although there was a good bit of reading in some applications and the user was required to close the message box by clicking OK.

In the back of my mind I always knew that this method was a bit of a kludge, and I wanted to provide a better solution. The biggest drawback to this “Help” solution, aside from everything being jammed into one big Help screen, was that it lacked a key feature that I and other users really wanted—the ability to copy some of the Help text and use it within the application. The most pointed example of this made itself known every time you had to enter a detailed query string into an application. Although the structured query strings that you could call on were visible and accessible by pressing the F1 key, there was no way to copy them from the message box and paste them directly into the application input boxes. Message boxes just don’t offer that type of functionality.

In my quest to learn more about HTML and to build better HTAs, I had seen some examples of using pop-ups within Web applications to display a variety of things. However, I couldn’t get pop-ups to work when I tried to write them using VBScript. I finally decided to try my hand at writing a pop-up function using JScript. Lo and behold it worked the first time around. JScript, as I see it, has a lot of similarities to VBScript. There are some basic structural differences but not so much that it should discourage you from giving JScript a try.

I recently used JScript in one of my NT admin HTAs and it worked beautifully. The nice thing about using a pop-up was that I could finally copy portions of the Help content and paste it right into an application input box. I was even able to write the rest of my code in VBScript because JScript and VBScript can coexist within the same application.

I’ve created a very basic HTA application (HTAPop-upHelp.hta) that demonstrates how to create not only a general application Help pop-up, but also context-sensitive Help screens. (You can download this HTA by clicking the Download the Code Here button.) Creating context-sensitive Help pop-up windows involves the following four steps:

  1. Identifying the form elements for which you want to have context-sensitive Help pop-ups and assigning an ID attribute to each one.
  2. Writing code that first determines which form element is active, then calls the corresponding function that displays the appropriate context-sensitive help.
  3. Creating the context-sensitive functions.
  4. Testing the context-sensitive Help pop-ups.

Assigning ID Attributes
To create context-sensitive help, I evaluate which form element the cursor is in when the user presses F1. One of the requirements to making a context-sensitive Help pop-up work is that you must assign an ID attribute to every form element (e.g., text boxes, drop-down boxes, radio buttons, text areas, check boxes) that you want to provide help on.

Assigning an ID attribute to a form element is easy. Simply include ID="someName" (where someName is the element's ID) within the HTML code for each element that you want to provide help on. The following is an example of one of the elements I used in the HTA that accompanies this article:

<input type="radio" id="Rad1" value="V1" name="R1">

In this command, I’m assigning one of my two radio buttons (or option buttons) the ID of "Rad1."

Determining Which Form Element Is Active and Calling the Corresponding Subroutine
Once the IDs are in place, you can determine which element is active (or where the cursor is) by evaluating the document’s active elements ID property using the command

document.activeElement.id

As callout A in Listing 1 shows, this command is used in a Select Case statement in a function named ShowHelp. The ShowHelp subroutine determines which function to call based on the value that the document.activeElement.id command returns. Depending on which Case clause is true, a call is made to the corresponding context-sensitive Help pop-up function. There’s a Case clause and a Help pop-up function for each form element that requires a context-sensitive Help pop-up.

The only other thing I’d like to mention about the code in Listing 1 pertains to the first Case statement Case "". This Case statement means that the cursor isn’t in any of the form elements; instead the user has clicked the HTA background, which has no ID associated with it. In that case, I just provide the general Help pop-up. Figure 1 shows an example of the general application pop-up window.

Creating the Context-Sensitive Functions
Within each function is a context-sensitive Help message comprised of plain-text and HTML formatting that gets stored in the HelpMessage variable. Listing 2 shows the function that displays the context-sensitive Help message in Figure 2. This function first writes the Help message. The function then creates the pop-up, sets the pop-up style and color, assigns the Help message to the innerHTML property, and shows the pop-up at the screen coordinates relative to your HTA window. Callout A in Listing 2 shows what the section of the function that creates and formats the pop-up looks like. The first two lines in callout A in Listing 2 set up two required pop-up objects—one for the pop-up and one for the pop-up body. The next few lines of code set the pop-up color scheme, after which the contents of the HelpMessage variable are assigned to the pop-up’s innerHTML property. Finally, the pop-up is displayed at the specified coordinates via the Show method. Figure 2 shows an example of a context-sensitive Help pop-up window.

You can set the pop-up window colors to almost any color you like. In the function in Listing 2, the first style setting sets the background color to teal, the second style setting sets the color of the text to white, and the third style setting sets the border to a layered black inset style with a thickness of 1 pixel. You can experiment with the style settings to get the look you want. Some other styles you can use include the ridge, groove, solid, and outset settings.

Testing a Help Pop-Up
To test the context-sensitive Help pop-up, simply launch it and place the cursor in any field, including the check boxes and radio buttons, and press F1. If you want to test the general Help pop-up, just click the HTA background away from any of the form elements and press F1.

Setting Up onhelp Events
As I mentioned previously, the onhelp event is also important to making the overall Help feature work. Setting up onhelp events is straightforward. To do so, simply add the following syntax to your opening <BODY> tag:

<Body onhelp=”ShowHelp”>

When you declare the onhelp event, you’re telling the HTA to execute the ShowHelp subroutine or function when the F1 key is pressed. My application calls a subroutine, but if you call a function you must include the open and close parentheses in the <BODY> tag, as shown in the following command:

<Body onhelp=”ShowHelp()”>

Providing Users with Helpful Information
Context-sensitive Help pop-ups offer you a quick and effective means of providing immediate assistance and guidance to your HTA. In fact, you can think of Help pop-ups as a quick reference guides that users can access with just the press of a key. I hope you’ll try using JScript to create context-sensitive Help pop-up windows for your HTAs.

End of Article



Reader Comments

You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
Friday at PASS Europe 2006

Kevin talks about the closing day of the event and shares a funny Microsoft film. ...

Escape From Yesterworld

Kevin points you to the funniest SQL Server website ever! ...

The Desktop tab is missing from the Display Properties in Windows XP?

...


Related Articles How to Learn and Even Master the Art of Writing HTAs

HTA F/X

Use an HTA as a UI for Your VBScript Scripts

Hooked on HTAs

Related Events Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.

Job Openings in IT


ADS BY GOOGLE SPONSORED LINKS FEATURED LINKS

WinConnections Conference Fall 2008
Don’t miss the premier event for Microsoft IT Professionals in Las Vegas, November 10-13. Register and book your room by August 25 and receive a FREE room night (based on a three night minimum stay).

Maximize your SharePoint Investment – 8 Cities
Discover best practices and tips for both architecting and administering SharePoint. Early Bird Price of $99 through Sept 15th.

Find a new job now on the all new IT Job Hound!
Search jobs, post your resume, and set up job e-mail alerts!

Master SharePoint with 3 eLearning Seminars
Learn how to build a better SharePoint infrastructure and enable powerful collaboration with MVPs Dan Holme and Michael Noel. Register today!

Top Tools for Virtualization Disaster Recovery & Replication
View this web seminar on August 14th to learn about two tools that will result in faster backup and restore with P2V disaster recovery.

SharePointConnections Conference Fall 2008
Don’t miss the premier event for Microsoft IT Professionals in Las Vegas, November 10-13. Register and book your room by August 25 and receive a FREE room night (based on a three night minimum stay).

VMworld 2008 - Sign Up Today!
Join your peers on September 15-18 at The Venetian Hotel in Las Vegas as VMware hosts VMworld 2008, the leading Virtualization event.



When managing just VMware isn’t enough
Plan/Manage/Secure – NetIQ VMware management. Download whitepaper.

What’s up with your network? Find out with ipMonitor
Availability monitoring for servers, applications and networks – FREE trial

Microsoft® Tech•Ed EMEA 2008 IT Professionals
Advance your thinking with new ideas and practical real-world solutions at Microsoft’s FIVE day technical infrastructure conference 3-7 Nov., 2008. Register before 26 September 2008 to save €300.

Order Your Fundamentals CD Today!
Gain an introduction to Exchange, learn server security requirements, and understand how unified communications can play a role in your messaging strategies with this free Exchange CD.

Are You Really Compliant with Software Regulations?
View this web seminar that will help you with compliance best practices and check out a management solution to assure that you won’t be in jeopardy of an audit.

Virtualization Congress Oct. 14-16 in London
Don't miss Virtualization Congress, the premiere EMEA conference dedicated to hardware, OS and application virtualization. Oct. 14-16 in London.
Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technical Resources Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing