how to do this

prashantSum's Avatar
I am using a popup window
in this I may be having n number of input checkboxes(here I have taken 4)
like this <input type='checkbox' name='comments1' value='0' />
so I will be naming it comments1, comments2, and so on.....

and now to return it's values to parent window I am using this function

function Done() {

if (comments1.checked)
MyArgs[1][0] = 1;
MyArgs[1][0] = 0;

if (comments2.checked)
MyArgs[1][1] = 1;
MyArgs[1][1] = 0;

if (comments3.checked)
MyArgs[1][2] = 1;
MyArgs[1][2] = 0;

if (comments4.checked)
MyArgs[1][3] = 1;
MyArgs[1][3] = 0;

window.returnValue = MyArgs;

now can do something like
if ( comments + i . checked) (not exactly like this )
I want to put it in a loop until the length of comments ( that is may be 1 .. 10, length I can determine) .
pradeep's Avatar, Join Date: Apr 2005
Team Leader
You can loop through the form elements and use a bit of regular expression to get as many checkbox values you want.

var myArgs[1] = {};
 fucntion Collect(oForm)
   var e=oForm.elements;
   for(var i=0;i<e.length;i++)
 	if(e[i].type="checkbox" && e[i].name.match(/^comments([\d]+)$/))
 		myArgs[1][RegExp.$1] = 1;
 		myArgs[1][RegExp.$1] = 0;
 //calling the function

Hope this is useful.
prashantSum's Avatar
thx for reply pradeep,

actually I have completed that task by some other way,

but what you have given is intresting I would like to work on it later...and ask any doubts

one immediate for me when I am looking at script is ( as not aware of RE in java script)
' RegExp.$1' do I need to place it as it is or is there any to I need to replace there..