Kappa Computer Solutions, LLC

Leveraging UNIX, GNU/Linux, open source, and
custom software solutions for business and beyond

Phone: 877•367•8837   Twitter: kappacs

Home arrow Articles
Articles
About Kappa Computer Solutions, LLC PDF Print E-mail

Overview

Kappa Computer Solutions, LLC is a small computer consulting company located in Northbrook, Illinois, about 25 miles north of the city of Chicago and 13 miles from O'Hare Airport.

Our specialties are:

  • UNIX and GNU/Linux installation, administration, and support
  • Perl- and PHP-based software (scripts/applications)
  • Intranets and internal web applications based on:
    • HTML (hyper-text markup language)
    • CSS (cascading style sheets)
    • JavaScript/ECMAScript (web browser client-side scripting)
  • Wrappers and extensions to existing software
While Microsoft Windows and Windows-based applications are not our specialty, we have been using them since Windows started shipping with PCs, and can provide support in these areas as well. We also have a strong Windows partner.

Types Of Clients

Our clients include businesses of all sizes in a wide range of industries, academic and research groups, government and military agencies, and other consulting companies.

Most are US-based. Some are international, and we have worked at client offices in Canada and Europe.

Some Reasons To Choose Us

  • Kappa Computer Solutions, LLC has been around for about 10 years. Brian Katzung, the founder and owner, has been in the business for more than 30 years.
  • We're a small company. Clients matter to us, and we tend to have strong, long-term business relationships with our clients.
  • A project that might be too small for a larger company probably won't be for us.
  • Bigger projects aren't a problem either. We have often supplemented a client's in-house staff or worked with our own partners on larger projects.
  • We're located in the United States. We speak American English and have US business hours.
  • If you happen to be located in or near the greater Chicagoland area, we are within driving range to provide you with on-site support.
 
FormRequest: Dynamic Form Parameters PDF Print E-mail

The Problem

Sometimes you want a particular form on a page to return different parameters or values depending on which button or javascript function is used to submit the form.

Here is a simple example:

<input type='submit' name='action' value='Stop' />
<input type='submit' name='action' value='Start' />

Whichever submit button is pressed is considered "active", and only its parameter and value are passed in the request ("action=Stop" or "action=Start").

If you want a graphic button instead of a text button, the example changes to something like this:

<button type='submit' name='action' value='Stop'>
<img src='stop.png' height='40' width='40' alt='Stop' /></button>
<button type='submit' name='action' value='Start'>
<img src='start.png' height='40' width='40' alt='Start' /></button>

This should work the same way as the textual submit buttons, and in some browsers it does. Unfortunately, some versions/document compatibility modes of Internet Explorer use the innerText of the button as its value, while IE6 considers all graphical submit buttons to be active, not just the one that was pressed (if any). Either way, it is likely that you will end up with an inappropriate request to the server.

 

Some Solutions

Where the use of javascript is acceptable, one work-around is to omit the name attribute from the button so that no value is directly passed in the request and to use a click handler to populate a hidden input according to which button has been pressed, as follows:

<input type='hidden' name='action' value='' />
<button type='submit' onclick='this.form.action.value="Stop"'>
<img src='stop.png' height='40' width='40' alt='Stop' /></button>
<button type='submit'
onclick='this.form.action.value="Start"'>
<img src='start.png' height='40' width='40' alt='Start' /></button>

A side effect of this approach is that there will now always be at least an empty value for "action", even if the form is submitted by some other means (e.g. javascript code or another submit button not using the variable "action").

In a very complex form, there could be quite a few "conditional" parameters. Of course, it is possible to create hidden inputs in advance for every possible value you might wish to submit with the form, along with special values, additional parameters, or some other context for server-side logic to determine which values should actually be used.

A slightly more sophisticated approach (also using and dependent on javascript) is to dynamically add hidden inputs to the document object model (DOM) for exactly the values you need for a particular request.

The "formRequest" function created by Brian Katzung of Kappa Computer Solutions, LLC makes this easy and convenient.

Continuing with the example from above, the code would look something like this:

<script type='text/javascript' src='formrequest.js'></script>
...
<button type='button' onclick='formRequest(this, { "action": "Stop" })'>
<img src='stop.png'
height='40' width='40' alt='Stop' /></button>
<button type='button' onclick='formRequest(this, { "action": "Start" })'>
<img src='start.png'
height='40' width='40' alt='Start' /></button>

In this example, the call to formRequest will dynamically add a hidden input with name "action" and a value of "Start" or "Stop", depending on which button is pressed. Note that the button type is now "button", not "submit", as formRequest will handle submitting the form. Like the original example, the "action" input will not exist in the request unless one of these buttons is used to submit the form or it is created elsewhere by other means.

 

FormRequest Details

If the first parameter is either a DOM form element or any element within the form that has a "form" property referencing the enclosing form, that form will be the recipient of the dynamically added hidden inputs. Otherwise, the first form on the page (document.forms[0]) is used.

Subsequent parameters should be objects whose attributes and values will be used to dynamically generate the hidden inputs. If the object is an array, the elements in the array are interpreted alternately as names and values instead.

If you need to pass multiple values for the same parameter, you can use an array of values or duplicate the key value (in an array object) as follows:

{ "name": [ "value1", "value2" ] }
[ "name", [ "value1", "value2" ] ]
[ "name", "value1", "name", "value2" ]

Special names "=action", "=enctype", "=method", and "=target" can be used to override the action URL, enctype (encoding type), method (GET or POST), or target window of the form for specific calls to formRequest.

If the target of the form is another window (either because of a target attribute in the original request or because of an "=target" setting in a formRequest), or if the form generates an AJAX request, the page will not be replaced and it is therefore possible for the form to be submitted multiple times as the result of additional user action. Subsequent calls to formRequest will undo the previous changes before processing the new formRequest. If you need to undo the changes in any other context, simply call "undoFormRequest()".

One final special name, "=confirm", prompts the user (using the value as the prompt) to confirm or cancel the form submission.

None of the special names or their values are passed in the request.

 
MenuPosition: Smart CSS/Javascript Hybrid Menus PDF Print E-mail

Overview

There are currently two common methods for placing drop-down and fly-out (or slide-out) menus in web designs. One is to use CSS (cascading style sheets) that place the menus and sub-menus when the mouse or other pointing device is held over a top-level menu item. The second is to capture mouse events and use Javascript to display and hide the menus.

CSS placement has the advantage that sub-menus can still function even if Javascript is not supported by the user's browser or has been disabled. It's disadvantage is that sub-menu items may appear beyond the current browser window edges, making them partially or completely inaccessible.

Use of Javascript has the advantage that sub-menus can be placed intelligently, taking into account where it appears in relation to the window edges. The disadvantage is that sub-menus will not appear at all if Javascript is disabled or not supported. 

Brian Katzung of Kappa Computer Solutions, LLC has developed a "smart", CSS/Javascript hybrid menu system called "menuposition" which combines the best of both approaches: basic CSS-based positioning when Javascript is not available or is disabled, and edge-aware Javascript-based positioning when Javascript is available and enabled.

Javascript is also used to overcome a "z-index" stacking issue in Internet Explorer that arises if sub-menus can overlap other menus (e.g. if top navigation drop-downs can overlap left-side navigation and left-side slide-outs can overlap top navigation).

Menu Structure and Javascript Linkage

Menus are structured using HTML nested unordered lists and lists items.

Sub-menus of vertical menus can be set to appear either to the right (for left-side menus) or to the left (for right-side menus), and will automatically reverse direction each time either side would be hit.

First-level sub-menus of horizontal menus are vertical menus and can be set to appear either below or above the horizontal menu, with second and subsequent sub-menus appearing either to the right or left, as above.

In order to avoid page-size-dependent setup overhead at page load time, javascript support uses a just-in-time approach based on mouse-over events at the top level <UL> of each menu (or an enclosing <DIV>).

The script file, menuposition.js, depends on another script from Kappa Computer Solutions, LLC, called viewport.js (based on code from quirksmode.org), and either prototype.js from prototypejs.org or mootools.js from mootools.net.

Configuration

Menu Direction

The direction in which sub-menus appear is determine using one of two methods.

The first (and preferred) method is the use of classes in the top-level <UL> or enclosing <DIV> tag. Horizontal top-level menus should include a class of "mpDown" or "mpUp" to specify whether first-level sub-menus should drop down or raise up from the base menu. Vertical menus, and horizontal menus with the potential to have more than one level of sub-menus, should include a class of "mpRight" or "mpLeft" to specify whether sub-menus should initially be staggered toward the right or left.

If only "mpDown" or "mpUp" is specified, the default for subsequent sub-menus is "mpRight".

A typical menu across the top of a page will have a class of "mpDown mpRight". A typical left-side menu will have a class of "mpRight".

If directional classes are not specified, menuposition will check the "float" style of list items in the menu. If there is a float style of either "left" or "right", the menu is assumed to be horizontal, and "mpDown" is used for the next level of sub-menus. Otherwise, the menu is assumed to be vertical, and "mpRight" is used for sub-menus.

Minimum Sub-Menu Overlap

Menuposition will make sure that sub-menus have at least window.mpMinOverlap pixels of overlap with the parent item (side-to-side if the parent menu is horizontal, or top-to-bottom if the parent menu is vertical). This space is used to guarantee that the user can move the mouse or other pointing device from the parent item to the sub-menu.

Brower Compatibility

The current version of menuposition has been tested with Firefox 1+ and Internet Explorer 6 and 7. It does not currently support work-arounds for versions of IE that don't properly display content overlapping form elements.

Joomla! Integration

Menuposition can be easily integrated into Joomla!-based web sites using Daniel Ecer's extended-menu module and a menu template.