JavaScript Page 2 - Just-in-Time Information and Ajax |
Example 4-4. JIT onfocus form help <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" var xmlhttp; aaManageEvent(window, 'load', function() { function showHelp(evnt) { function printHelp() { //]]> <label for="lastname">Last Name:</label><br /> <input type="submit" value="Save" /> </fieldset> This is a very simple approach to dynamically providing help. With just the two fields, neither of which really need additional explanation, you wouldn't normally use this approach, but the simplicity does provide a clear demonstration. The server component of the Ajax application is equally as simple: <?php echo $result; However, if you have several forms spread out over several pages, providing the same help system to all of the pages allows you to make modifications in the help text in one place instead of in each of several different pages. This approach then becomes much more viable. Additionally, if the application caches the lookup information when it's retrieved the first time, the connections to the server are decreased: function printHelp() { With the caching modification, the application tests for the existence of the help item in the associative array cache. Another improvement is to make the help more "on-demand," rather than putting it up only when the page reader enters a field. One way to do this is to capture the click event for the labels rather than the focus event for the fields, and display help when the labels are clicked: function setUp() { For this approach to work, the labels are given identifiers, rather than the form fields: <form action="ch04-05.htm" method="post"> A problem with using the labels is there's no way to know that they're clickable. One way around this is to add a mouseover effect to the label, setting the mouse pointer to a question mark. Do this by adding a CSS stylesheet setting to change the mouse pointer to the help cursor (typically a question mark) whenever it is placed over a label: label { cursor: help; } Of course, you still have to know to move your mouse over the label to get the cursor. Plus, you have to be using a mouse to realize that the label has a different cursor, and you must have script enabled. A more unobtrusive and intuitive approach would be to surround the labels with a hypertext link, set the target attribute to a new window name, and display the help based on the mouseover event rather than the click. If scripting is enabled, the mouseover displays the help. If scripting is not enabled, the hypertext link opens a separate window with the help information. This change makes the JIT help "keyboard-enabled" and more accessible for screen readers.
blog comments powered by Disqus |
|
|
|
|
|
|
|