Obtaining Checkbox Fieldnames in agent using Javascript

I have an agent which picks up all of the documents in the database and displays them with a checkbox. The documents are categorized as such (think of - as a checkbox):

  • Operation

    • Componenet

      • Action Item

      • Action Item

When the user selects the Operation checkbox (fieldname = A), I want to select all of the corosponding Components (fieldname = A_1, A_2,…) and Action Items (fieldname = A_1_UniqueID, A_1_UniqueID,…)

I am doing this in JavaScript. My question is this - I know that if the checkbox being selected is an Operation, I need to find all of the components and action item checkboxes on the form (remember, the form was generated by an agent - so it is not really a form!) that contain the Operation name in the fieldname.

if instr(1,field,namepassed)<>0 then

check the field

How can I set this up in javascript? How can I loop through all of the fields that were generated?

Any ideas or suggestions would be greatly appreciated - thanks in advance.

Subject: Obtaining Checkbox Fieldnames in agent using Javascript

Can’t you iterate throught the fields using document.forms[0].elements? If your HTML is correct, with form tags etc, it should work. Use it like this (not tested):

var a=document.forms[0].elements;

for(i=0;i<a.length;i++){

e=a[i];

if(e.type=='checkbox'){

	//do something

}else if(e.type=='radio'){

	//do something else

}else{

	//do something completely different

}

}

  • Johan

johan@kanngard.net

http://dev.kanngard.net