The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Javascript, Forms, and counting occurences of identical Names

I'm trying to make a form where a user can check boxes, and depending on if certain boxes have been checked, other boxes will grey out or un-grey.

What the code does is look at the checkbox name and depending on the family (f), and whether or not the box is a child (c) or a parent (p), the code will grey out certain boxes.

Now that I've sat back and thought about the code, I think there is probably a better way to achieve what I want.

Maybe I can specify checkbox names instead of doing the parent child hierarchy that i'm trying.

Any suggestions?

This is what I have so far, but it's getting complicated.

Code:

function evaluateFormOptions(e)
{
var e = event || e;
var checkbox = e.srcElement || e.target;
var formElements = document.forms["myForm"].elements;
getNumberOfFamilies(formElements);
}
function getNumberOfFamilies(formElements)
///////////////////////////////////////////////////////////////////////////////
// gets the number of families //
// Function only supports single character family and child values right now //
///////////////////////////////////////////////////////////////////////////////
{
for (var formOptionsArrayIndex = 0; formOptionsArrayIndex < formElements.length; formOptionsArrayIndex++ )
{
// get position of family character then get the family character
var familyNumberPosition = formElements[formOptionsArrayIndex].name.indexOf('f') + 1;
var familyNumber = formElements[formOptionsArrayIndex].name.charAt(familyNumberPosition);
// set up the familyArray so it's length can be counted later
var familyArray = new Array();
// add familyNumber to the familyArray
for (formOptionsArrayIndex = 0; formOptionsArrayIndex < formElements.length; formOptionsArrayIndex++)
{
//check if array already has family number in it, if not add the family number to the array
if (familyArray.indexOf(familyNumber) == '-1')
{
//add another space in the array and put the new family number in it
var newItemPosition = familyArray.length;
familyArray.length = familyArray.length + 1;
familyArray.[newItemPosition] = familyNumber;
}
}
}
alert(familyArray.length);
}