Form Dependency Manager
Updated: 22/09/06. Added "EMPTY" keyword. Script no longer tramples over existing events on the form elements.
An overview of this script:
All dependency logic is defined via the
classattribute inside the form fields in question, for easy implementation.
- Create dependency based on the value (ie: text fields) or state (ie: radio boxes) of another field. Use "OR" or "AND" to create more complex dependencies.
Demo: Make your selections:
Step 1: Add the below code to the <HEAD> section of your page:
The above code references an external .js file, which you need to download: FormManager.js (right click, and select "Save As").
Step 2: Then, add the below sample form to your page:
This is an example web hosting signup form. It offers options of Windows or Linux hosting. If Windows, the client can choose Apache or IIS, and optional frequent crashes. If the client decides that s/he wants IIS, s/he has the option of ASP, and insecurity. The alternative is Apache, which is also available on Linux, as is SSH access. Obviously, the client cannot choose two webserver packages. It also gives an example of how to hide text using a label and hidden form element, and how to depend on a variable-value element.
The script uses a simple syntax to implement dependency amongst form fields, by utilising the class attribute. There are two basic types of statements:
DEPENDS ON name [BEING value] [OR name [BEING value]] CONFLICTS WITH name [BEING value]
Multiple statements can be separated with the
"AND" can also be used to mark the boundary between these
statements and true CSS classes, so the script doesn't interfere with your
stylesheets. There is also a special keyword for use after
EMPTY. Study the
sample HTML code of Step 2 to see how it works, or post any questions in