|
-
Sep 9th, 2005, 10:48 AM
#1
Thread Starter
Addicted Member
Retrieving opening page's form name
I was hoping someone could help me with a problem I am having.
I am using Javascript to pass values back from a popup window to the calling webpage like so:
window.opener.document.forms[0].txtName.value = document.forms[0].txtName.value;
This works just fine, except when the opening webpage has more than one form on it, then I would have to explicitly call the form by it's name rather than the subscript 0.
What I was hoping to do was to programmatically retrieve the name of the form the element resides on so that it wouldn't matter what the form name was called.
Is there anyway to do this?
Thanks
-
Sep 10th, 2005, 10:53 AM
#2
Re: Retrieving opening page's form name
You would need to loop through the forms array an look for an element named txtName after the window has opened:
Code:
var formsP = window.opener.document.forms;
var targetForm;
var searchField = 'txtName';
for(var x =0; formsP.length; x++)
{
if (formsP[x].elements[searchField]) {
targetForm = formsP[x];
break;
}
}
-
Sep 12th, 2005, 09:04 AM
#3
Thread Starter
Addicted Member
Re: Retrieving opening page's form name
Thanks, I will definetly give this a try. The other guy I work with here, suggested something along those lines, but I had no idea how to do it.
Thanks for your help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|