Form Help DOM/JavaScript

Form Help Unobtrusive DOM/JavaScript Code

Linking to the external DOM/JavaScript file

Put a link to the Unobtrusive DOM/JavaScript file in the <head></head> section of the web page.

Definitions of the highlighted markup:
<head></head> This markup element contains the <script></script> element that holds the relative path to the DOM/JavaScript file.
src="scripts/formhelp.js" This markup attribute of the <script></script> element contains the relative path to the external source (src) location of the DOM/JavaScript file.

Important Note: All files must always be kept within the main project folder to maintain their associations as written in the code.

  1. <head>
  2.   <script type="text/javascript" src="scripts/formhelp.js"></script>
  3. </head>

top

Employ this Unobtrusive DOM/JavaScript to initiate Context-Sensitive Form Help.

The external DOM/JavaScript code sets a hook to the rel attribute value of "help" in the <a></a> element with its href attribute to open the Context-Sensitive help web page (HelpExample.htm) within the Form Help Method web page.

The following code block contains three functions:

  1. /* start multiple load function - design by Simon Willison */
  2. function addLoadEvent(func) {
  3.   var oldonload = window.onload;
  4.   if (typeof window.onload != 'function') {
  5.     window.onload = func;
  6.   } else {
  7.     window.onload = function() {
  8.       if (oldonload) {
  9.         oldonload();
  10.       }
  11.       func();
  12.     }
  13.   }
  14. }
  15. addLoadEvent(window.onload);
  16. addLoadEvent(function() { 
  17. /* add more code here to run on page load if necessary */
  18. });
  19. /* end multiple load function */
  20.  
  21. /* start window.onload = function() */
  22. window.onload = function() {
  23.   if (!document.getElementsByTagName) return false;
  24.     var lnks = document.getElementsByTagName("a");
  25.     for (var i=0; i<lnks.length; i++) {
  26.   if (lnks[i].getAttribute("rel") == "help") {
  27.     lnks[i].onclick = function() {
  28.       popUp(this.getAttribute("href"));
  29.       return false;
  30.       }
  31.     }
  32.   }
  33. }
  34. /* end formhelp() function */
  35.  
  36. /* start popUp(winURL) function */
  37. function popUp(winURL) {
  38.   window.open(winURL,"popup","width=460,height=680,status=yes,resizable=yes,scrollbars=yes,screenX=600,screenY=200,top=200,left=600");
  39. }
  40. /* end popUp(winURL) function */

top