Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array of fields(checkboxes) to update

Status
Not open for further replies.

jkafer

Technical User
Feb 13, 2004
32
US
I'm stumped and I think I've just been looking at this too long and I'm missing something simple:

I have an array of fields that I would like to update if the function is called.

The array will change - that part is working the sample I'm going to show is after the array is selected I want to update all checkboxes in that array to be checked.

var theGroup = ['typM', 'typSt', 'typSp'];

for (i=0; i < theGroup.length;i++)
{
update field to checked. Here's the problem.
}

This works:
document.form1.typM.checked = true;
This does not:
document.form1.theGroup.checked = true;

If I do an alert(theGroup); it does loop through the array.

WHAT AM I MISSING?!?!??!

jeni
 
Basically what you are saying there is for the JS to look for a group of elements named theGroup inside the form named form1. But there are no elements with the name "theGroup" because that's a variable, so it can't find an object to reference.

Try this instead:
Code:
 document.form1.[red]elements[[/red]theGroup[i][red]][/red].checked = true;

You want to look for the elements who's names you want to get from the variable theGroup which is an array.







----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
PERFECT - told you I was looking at it too long!

This group rocks!
 
Hi

Here on Tek-Tips we used to thank for the received help by giving stars. Please click the

* [navy]Thank vacunita
for this valuable post![/navy]


at the bottom of vacunita's post. That way you both show your gratitude and indicate this thread as helpful.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top