Morphic Molecules
Control Arrays
These pages and Morphic Molecules Components, VBX's, XCMDs, and images are
Copyright Mona M. Everett, Ph.D., 1995-1998
everett@cyberramp.net




Visual Basic programmers are familiar with control arrays but they may be unfamiliar to users of other languages. Control arrays are generally characterized by having a number of controls which have the same name and are then referred to via an index. Like other Javascript indices, control array indices range from 0 to n; i.e., they are zero-based but the zero index holds the array length. Unfortunately, unlike VB control arrays, Javascript control arrays do not return an index when they are clicked unless you specifically program it into the value or an onclick handler.

Although the Javascript control array which is best documented is that for radiobuttons, other controls can be arrayed as well.

This little form has nine checkboxes. Each has the name 'checkArray'. Each has also been assigned a value equivalent to the spelled out number of its index. The zero index holds array length. When you click the button, a function will attempt to tell you which ones are checked by iterating through the control array.
 

(1)The array is recognized and the function can tell me the number of controls in it.
(2)The array name is undefined.
(3)The value of any member of the array is defined.
(4)In Netscape 2.0x, the order of the array elements MAY appear backwards. If this happens, include a dummy 'onclick' handler for each button and the array will line up correctly.


one two three four five six seven eight nine

Script

Enter your three favorite fruits here:



 

You can also have control arrays of textboxes. Try changing the values of some of the text boxes on the left and pressing the Confirm button, just to prove that it works.

Script


Although this might be done more neatly with an image map, this exercise uses an array of buttons to form a calculator. The 'P' key lets you set decimal places but this feature is not implemented in this tiny example.

Script



This page was last updated on

Mail comments about Morphic Molecules pages to everett@cyberramp.net