Results 1 to 3 of 3

Thread: Retrieving opening page's form name

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Posts
    149

    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

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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;
        }
    }
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Posts
    149

    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
  •  



Click Here to Expand Forum to Full Width