/    Sign up×
Community /Pin to ProfileBookmark

Passing values between 2 windows

Hi,

i have the following problem, hope you can help me.

i have a webpage with a form on it to enter data. Now a lot of the standard data is already in a database, so i would like to add a link next to the form that enables me:

  • to open a pop up window

  • which shows me the standard data from the database

  • by clicking on one dataset in the list menu, the values are passed to the “parent” website and shown in the various form fields.
  • so far i have seen scripts out there that can do this – however i need to pass not only one value, but a few more since my recordsets contain various fields (street, zip, city, etc).

    how can i do this? do you have examples available?

    thx mark

    to post a comment
    JavaScript

    5 Comments(s)

    Copy linkTweet thisAlerts:
    @KorApr 14.2005 — to reach an object (thus to dynamically modify it's attributes) from a popup to "parent" (opener) you may use the generic reference

    opener.document.[i]object[/i]

    if it is a textfield in a form, for instance, it is to be reach as

    opener.document.forms['formname'].elements['textfieldname']

    or, simply by it's id

    opener.document.getElementById('textfieldid')
    Copy linkTweet thisAlerts:
    @smarksauthorApr 14.2005 — can you give an example code line how i can store the values of the pop up and then transfer them to the parent window?

    i basically select one recordset on the pop-up (ie. an address), but a couple of values have to be stored in several javascript fields that i then transfer over to the parent window (ie. street, zip, city, etc).

    your help is appreciated

    thx mark
    Copy linkTweet thisAlerts:
    @KorApr 14.2005 — index html (the opener)
    [code=php]
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <script type="text/JavaScript">
    onload=function(){
    window.open('pop.html','','width=300,height=300')
    }
    </script>
    </head>
    <body>
    <div id="txt">&nbsp;</div>
    </body>
    </html>
    [/code]


    pop.html (the popup)
    [code=php]
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <script type="text/JavaScript">
    function sendD(s){
    opener.document.getElementById('txt').firstChild.data = s.firstChild.data;
    }
    </script>
    <style type="text/css">
    <!--
    span {
    background-color: #99CCFF;
    cursor:pointer;
    }
    -->
    </style>
    </head>
    <body>
    Click on text to send it to the opener:
    <br><br>
    <span onclick="sendD(this)">Jethro Tull | Aqualung</span><br><br>
    <span onclick="sendD(this)">Led Zeppelin | Stairway to Heaven</span><br><br>
    <span onclick="sendD(this)">Marillion | Fugazi</span>
    </body>
    </html>
    [/code]


    Remove the space in firstChild.d ata . Should be firstChild.data
    Copy linkTweet thisAlerts:
    @smarksauthorApr 14.2005 — ok, thanks for this example.

    now by clicking on the "Jethro Tull" link - how can i populate 2 text fields on the parent site, one with Jethro Tull, and the other with Aqualung. how can i split this up?

    please let me know,

    thx mark
    Copy linkTweet thisAlerts:
    @KorApr 14.2005 — using split() method. Well it is up to your HTML coding. For my example it will be something like

    index
    [code=php]
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <script type="text/JavaScript">
    onload=function(){
    window.open('pop.html','','width=300,height=300')
    }
    </script>
    </head>
    <body>
    <input id="txt1" type="text"><br>
    <input id="txt2" type="text">

    </body>
    </html>
    [/code]


    in popup
    [code=php]
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <script type="text/JavaScript">
    function sendD(s){
    var tx = s.firstChild.data.split(' | ');
    opener.document.getElementById('txt1').value= tx[0];
    opener.document.getElementById('txt2').value= tx[1];
    }
    </script>
    <style type="text/css">
    <!--
    span {
    background-color: #99CCFF;
    cursor:pointer;
    }
    -->
    </style>
    </head>
    <body>
    Click on text to send it to the opener:
    <br><br>
    <span onclick="sendD(this)">Jethro Tull | Aqualung</span><br><br>
    <span onclick="sendD(this)">Led Zeppelin | Stairway to Heaven</span><br><br>
    <span onclick="sendD(this)">Marillion | Fugazi</span>
    </body>
    </html>
    [/code]


    I just try to show you the principle of transfering data from a pop to opener. The way you [b]insert[/b] the transfered data is up to your HTML codes and your needs
    ×

    Success!

    Help @smarks spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.17,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...