SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    monitormensch oerdec's Avatar
    Join Date
    Sep 2004
    Location
    Hamburg
    Posts
    706
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    passing POST data from popup to main window

    Hello,

    I want a popup window with a form in it. When a button is pressed the window should close and all form data has to be passed to the main window. In that window there is no form. I just need the POST data as I had sent it directly to it.

    It would be great if anyone could help me.

    oerdec

    [edit]

    OK, I know how to pass data into a form field of the parent window...

    HTML in my popup:
    HTML Code:
    <input type="button" value="pass" onclick="pass('hallo')" />
    JavaScript function in popup
    Code:
    function pass(text) { 
      window.opener.document.getElementById('target').value = text;
      window.close();
    }
    HTML in main window:
    HTML Code:
    <input type="text" id="target" />

    But what can I do if there is no form in the main window? I need the POST data for further processing with PHP.
    Last edited by oerdec; Feb 2, 2007 at 13:32.

  2. #2
    SitePoint Addict ALL's Avatar
    Join Date
    Oct 2005
    Location
    South Dakota
    Posts
    215
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by oerdec View Post
    Hello,

    I want a popup window with a form in it. When a button is pressed the window should close and all form data has to be passed to the main window. In that window there is no form. I just need the POST data as I had sent it directly to it.

    It would be great if anyone could help me.

    oerdec

    [edit]

    OK, I know how to pass data into a form field of the parent window...

    HTML in my popup:
    HTML Code:
    <input type="button" value="pass" onclick="pass('hallo')" />
    JavaScript function in popup
    Code:
    function pass(text) { 
      window.opener.document.getElementById('target').value = text;
      window.close();
    }
    HTML in main window:
    HTML Code:
    <input type="text" id="target" />

    But what can I do if there is no form in the main window? I need the POST data for further processing with PHP.
    The absolute eassiest way is to do this:

    HTML Code:
    <form method="POST" target="_blank" action="http://www.wikijs.com"> .........
    This will cause it to open in a new window when submitted. but if you absolutley have to use javascript to do it... you can do an "onsubmit" event have it create the window, when the window loads have it read the info from the parent window into it's form, then have it submit it.

    If you dont want to do that you might consider passing the info as a GET.

    -ALL
    Did I help you?
    You can repay me, support one of my projects (no money needed):
    JavaScript Wiki, Another Web Forum, Paranormal Site

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But what can I do if there is no form in the main window?
    Create one with hidden form fields.

    The only other way to send POST data to the server is by making an XMLHttpRequest.

  4. #4
    monitormensch oerdec's Avatar
    Join Date
    Sep 2004
    Location
    Hamburg
    Posts
    706
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you guys for your replies.

    @ALL: The form should not open a new window. Instead it has to close the active popup window and pass the data to the opener, the main window.

    @7stud: A hidden form field was no option because there was actually no HTML. I wanted to pass the POST data to a PHP script. I tried AJAX but didnīt get it working.

    OK, I have rewritten some parts of my app and came to a fairly simple solution. At first Iīm using GET now... and a JavaScript redirection. It looks basically like this:

    HTML Code:
    <input type="submit" value="pass" onclick="passID(123);" />
    Code:
      function passID(id) {
        window.close();
        window.opener.location.href = 'my_script/' + id;
      }
    This was just another example of "why simple when you can make it complicated"

    oerdec

  5. #5
    SitePoint Member
    Join Date
    Feb 2007
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    function update_parent() 
    { 
            window.opener.reload(); 
            window.close(); 
    }

    HTML Code:
    <form name="myform" action="run.php" method="get" 
    onSubmit="javascript:update_parent()">

    Code:
    function update_parent2(url) 
    {

    Try this & tell me about the result

    Good luck !


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
  •