SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member PerlWarrior's Avatar
    Join Date
    Sep 2003
    Location
    NC, USA
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy How do I set the value of a hidden form field in a popup?

    I need to set the value of a hidden field in a popup. The code that created the popup is:

    var a_id;
    function Wait_W001(urlpop,id)
    {
    popupurl = urlpop;
    a_id = id;
    setTimeout('PopWidnow(popupurl)', 7000);
    }

    function PopWidnow(url_pop)
    {
    var PopWidth=500;
    var PopHeight=460;
    var PopLeft=10;
    var PopTop=10;
    var subpop; subpop=window.open(url_pop,'subpop','toolbar=no,status=no,menubar=no,location=no,directories=no,resizable=yes,scrollbars=no,width='+PopWidth+',height='+PopHeight+',top='+PopTop+',left='+PopLeft);
    }

    The timer for the popup is triggered by:
    <BODY onLoad="Wait_W001('subpop.html',56789)" in the main window.

    So, the popup is created and the contents of subpop.html are then written into it...

    {Note: The hard-coded value passed to "id" in of Wait_W001(urlpop,id) will eventually be injected into the main page, most likely by using Perl or
    PHP to generate the main page. For now, though, my problem is in the
    popup window.}

    I need to set the value for this hidden input:
    <INPUT TYPE="hidden" NAME="aff_id" VALUE="">
    in the form named "popform" in the popup window.

    I wrote this code (and put it inside the BODY tag of the popup):

    <script language=JavaScript type="Text/JavaScript">
    var id;
    id=window.opener.a_id;
    document.popform.aff_id=id;
    </script>

    to get the value of [var] a_id from the opening window using the window.opener method and use it to set the value of the aff_id form input field to the value accessed from the parent window.

    Here's the opening FORM tag for reference:
    <FORM METHOD="POST" NAME="popform" ACTION="bnbform11.cgi" ENCTYPE="x-www-form-urlencoded">

    This just doesn't work. What am I doing wrong? Any help would be very much appreciated.

    PerlWarrior

  2. #2
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Should the line that sets the value of your ID read something like:
    Code:
    id=window.opener.getElementById('a_id').value;
    I definitely think that you'd have more luck if you set the next line to be:
    Code:
    document.getElementById('aff_id').value=id
    or something like that.

    Andy
    From the English nation to a US location.

  3. #3
    SitePoint Member PerlWarrior's Avatar
    Join Date
    Sep 2003
    Location
    NC, USA
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Andy.

    Now I have this:

    <script language=JavaScript type="Text/JavaScript">
    var id, aff_id;
    id=window.opener.getElementById('a_id').value;
    document.getElementById('aff_id').value=id;
    </script>

    I get the following runtime error:
    Line 12:
    Object doesn't support this property or method

    and the debugger stops on this line:
    id=window.opener.getElementById('a_id').value;

    If I hard-code a value for id, to see what the next line will do with 'id', like this:

    <script language=JavaScript type="Text/JavaScript">
    var id, aff_id;
    //id=window.opener.getElementById('a_id').value;
    id = 12345;
    document.getElementById('aff_id').value=id;
    </script>

    I get this error:
    Line 14:
    'document.getElementById(...)' is null or not an object.
    and the debugger stops on this line:
    document.getElementById('aff_id').value=id;

    Any ideas?

    Thanks in advance

  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try...
    Code:
    id=window.opener.document.getElementById('a_id').value;

  5. #5
    SitePoint Member PerlWarrior's Avatar
    Join Date
    Sep 2003
    Location
    NC, USA
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Mike.

    With this code:

    <body bgcolor="#fffcb9" leftmargin="0" topmargin="10" marginwidth="0" marginheight="0">
    <FORM METHOD="POST" NAME="popform" ACTION="http://realestatemoneymaker.com/cgi-bin/bnbform/bnbform11.cgi" ENCTYPE="x-www-form-urlencoded">
    <script language=JavaScript type="Text/JavaScript">
    var id, aff_id; id=window.opener.document.getElementById('a_id').value;
    //id = 12345;
    //document.getElementById('aff_id').value=id;
    </script>

    I get "Error: Object required" abd trhe debugger stops here:
    id=window.opener.document.getElementById('a_id').value;

    Could it be a problem in the main window (index.html)?

  6. #6
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ould it be a problem in the main window (index.html)?
    Yes, here's a few ideas...

    (1) Don't use underscores in id names.

    (2) Does index.html use frames?

    (3) Verify that the form control has the correct id.

    (4) Add some error checking...
    Code:
    if (window.opener) {
      if (window.opener.document) {
        if (window.opener.document.getElementById) {
          var e = window.opener.document.getElementById('a_id');
          if (e) {
            id = e.value;
          }
          else alert('a_id doesn't exist');
        }
        else alert('window.opener.document.getElementById is null');
      }
      else alert('window.opener.document is null');
    }
    else alert('window.opener is null');


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •