[Javascript] request for assistance...

jsWalter jsWalter at torres.ws
Fri Apr 9 17:41:52 CDT 2004


I'm a bit stumped.

I need to dynamically create an assoc array

Below is the code I have so far.

What I'm looking to do is loop through all FORM elements, pull out the
INPUT->CHECKBOX types and store them in an assoc array by FAMILY [custom]
attribute value

 - new FAMILY name, new key
 - same FAMILY name, new item to key

Anyone have a quick answer?

Thanks

Walter


======================================================================

<label for="cb1a"><input type="checkbox" family="rb1" name="cb1" id="cb1a"
value="a"> a</label>
<label for="cb1b"><input type="checkbox" family="rb1" name="cb1" id="cb1b"
value="b"> b</label>
<p />

<label for="cb2a"><input type="checkbox" family="rb2" name="cb2" id="cb2a"
value="1"> 1</label>
<label for="cb2b"><input type="checkbox" family="rb2" name="cb2" id="cb2b"
value="2"> 2</label>
<p />

<label for="zz"><input type="checkbox" name="zz" id="zz" value="z">
z</label>
</form>

<script type="text/javascript">

// get the first FORM of this document
var form = document.forms[0];

// create new Array
var aryCkFamily = new Array();

// initialize Object counter
var y = 0;

// loop through all FORM Objects
for (var i = 0; i < form.length ; i++)
{
	// We are looking for INPUT Objects with
	// the TYPE of CHECKBOX.
	// We are also looking for TEXTAREA Objects
	if ( ( form.elements[i].nodeName.toLowerCase() == "input" ) &&
				( form.elements[i].type.toLowerCase() == "checkbox" ) )
	{
		// We only this CHECKBOX if it has out FAMILY attribute
		if ( form.elements[i].getAttribute('family') )
		{
			// NOTE: Here...
			// need code to add new INPUT CHECKBOX objects into
			// associative array by FAMILY attribute value
			// - new FAMILY name, new key
			// - same FAMILY name, new item to key
		}
	}
}





More information about the Javascript mailing list