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;
else
MyArgs[1][0] = 0;
if (comments2.checked)
MyArgs[1][1] = 1;
else
MyArgs[1][1] = 0;
if (comments3.checked)
MyArgs[1][2] = 1;
else
MyArgs[1][2] = 0;
if (comments4.checked)
MyArgs[1][3] = 1;
else
MyArgs[1][3] = 0;
window.returnValue = MyArgs;
window.close();
}
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) .
|
Team Leader
|
![]() |
| 18Nov2005,12:41 | #2 |
|
You can loop through the form elements and use a bit of regular expression to get as many checkbox values you want.
Example: Code:
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]+)$/))
{
if(e[i].checked)
myArgs[1][RegExp.$1] = 1;
else
myArgs[1][RegExp.$1] = 0;
}
}
//calling the function
Collect(document.forms[0]);
Hope this is useful. http://spradeep.blogspot.com |
|
Contributor
|
|
| 18Nov2005,17:15 | #3 |
|
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.. |

