[Javascript] request for assistance... -- associative arrays
jsWalter
jsWalter at torres.ws
Sat Apr 10 11:39:45 CDT 2004
Thanks to all who offered assistance.
This is really a wonderful group.
This is the solution I have (thx Alex)
Very simple and straight forward.
Each "family" of Check boxes is collected into its own array, and a
reference to each member of that "family" is stored in that "family" array.
Very nice. Direct access to each Form Element. No additional references or
what not.
Very cross browser.
Thought I'd share, since I asked.
Walter
==========================================================================
var form = document.forms[0]; // get the first FORM of this document
var aryCkFamily = new Array(); // create new Array
// loop through all FORM Objects
for (var i = 0; i < form.length ; i++)
{
if ((form.elements[i].nodeName.toLowerCase() == "input") &&
(form.elements[i].type.toLowerCase() == "checkbox"))
{
// We only need this CHECKBOX if it has our FAMILY attribute
if (form.elements[i].getAttribute('family'))
{
// Pull family name
strFamily = form.elements[i].getAttribute('family');
// If this is a "new" family, than add it to the list of families
if (!aryCkFamily[strFamily])
aryCkFamily[strFamily] = new Array();
// Stick this object into its family array
aryCkFamily[strFamily].push(form.elements[i]);
}
}
}
More information about the Javascript
mailing list