#1
  1. Wiking
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Sep 2000
    Location
    Sweden
    Posts
    3,608
    Rep Power
    27
    This is just another post on the subject Javascript/PHP, and thus maybe not in the right forum, but anyway: Can someone help me in creating a popup window with variables from an array in PHP?

    I've got this table on a page which is fetched from a db to an array and then echoed through PHP. In the table I want links (with a variable from the table) to a popup window with details about things in the table.

    I can do a popup window with JS and PHP like this:
    <head>
    <script language="JavaScript" type="text/javascript">
    <!--
    function popup()
    {
    window.open("match_detalj.php3?id=200003", "popup", width="300, height=300");
    }
    //-->
    </script>
    </head>

    And call it in the <body>:
    <a href="javascript opup();">detaljer</a>

    But I just can't get it right it when I use an array to get info from a db and want links with the corresponding variable like this:

    ....
    while ($r = mysql_fetch_array($result)) {
    $mat = $r["matchnr"];

    // If I was to do the link without a popup window I'd use this:
    echo "<td width="200" class="gultabell" valign="top"><a href="match_detalj.php3?id=".$r["matchnr"]."">detaljer</a></td>";
    // And the tricky part which is wrong but just to get the idea
    echo "<td width="200" class="gultabell" valign="top"><a href="javascript opup();">detaljer</a></td>";
    ...

    Any thoughts about this?

    /NoXcuz
  2. #2
  3. Wiking
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Sep 2000
    Location
    Sweden
    Posts
    3,608
    Rep Power
    27
    Whooops, forgot to disable those smilies, but you gotta love 'em....

    I think you get it anyway, but it should have been
    <a href="javascriptopup();">

    /NoXcuz
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    Well I would do almost what you did but change jsut a few things like you would want to pass the id number to the javascript so you could do:

    while ($r = mysql_fetch_array($result)) {
    $opener = sprintf("window.open('match_detalj.php3?id=%s', 'popup','width=300,height=300'); ", $r["matchnr"]);
    printf('<td width="200" class="gultabell" valign="top"><a href="javascript:%s">detaljer</a></td>', $opener);



    [This message has been edited by freddydoesphp (edited October 30, 2000).]
  6. #4
  7. No Profile Picture
    Robert_J_Sherman
    Guest
    Devshed Newbie (0 - 499 posts)
    Call me nuts but judging from the example(s), the "value" of ID is not going to be passed via the link.. also for your JS link I'd probably go with an "onClick" event rather than a js:xxxx href=""...

    I'd probably work it more like so:
    <a href="javascript:void(0);" onClick="popup('<?php echo $id; ?>');">details</a>

    My JS would probably look more like:
    function popup(id) {
    }

    so that I can pass the value of "id" to the script.. making my script more versatile and usefull "across" my site.

    I think that's what Freddy was trying to get at..

    granted, from the same token, you PHP could generate the JS on the page too, so you don't have to pass anything to the JS.

    Really comes down to your preference, you could go about it a number of ways...



    ------------------
    SnR Graphics,
    Low Cost Hosting and Web Development.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    Yes to tell you the truth I got lazy, I usually create a function that any link could call upon from the page anywhere, but I got lazy on how to take the id passed from the onClick event to the js into the js code itself. Robert, would it be
    function popup(id)
    {
    window.open('match_detalj.php3?id=' + id + '', 'popup', 'width=300, height=300');
    }


    [This message has been edited by freddydoesphp (edited October 30, 2000).]
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    1
    Rep Power
    0
    Any ideas on how to pass dynamically generated dimensions to the pop-up window??

IMN logo majestic logo threadwatch logo seochat tools logo