#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    Boston
    Posts
    261
    Rep Power
    13

    passing php vars through javascript


    I have this script:

    PHP Code:
    <SCRIPT LANGUAGE="JavaScript">
    <!-- 
    Begin
    function openWin(URL){
    aWindow=window.open(URL"window""toolbar=no, width=350, height=500,status=no, scrollbars=no,resize=no,menubar=no");
    }
    //  End -->
    </script> 
    and am using this to call it:
    PHP Code:
    <a href="Javascript: openWin('page.php');">Click Here</a
    I need to pass a php variable to the new window. I have tried this:
    PHP Code:
    <a href="Javascript: openWin('page.php?var=<? print($var); ?>');">Click Here</a>
    but that didn't work. Anyone else know how to do this?

    Any assistance is greatly appreciated.
  2. #2
  3. No Profile Picture
    Not there when you need me
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Oct 2001
    Location
    Berlin, Germany
    Posts
    1,430
    Rep Power
    14
    Umm ... does that JavaScript thing work at all? I mean, if you have a line like
    Code:
    <a href="java script: openWin('page.php');">Click Here</a>
    , does it work at all?

    Second guess: do you define $var anywhere? If so, how?

    Have a look at the source of that page, perhaps you'll see what's wrong ...
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jul 2001
    Location
    Oslo
    Posts
    1,516
    Rep Power
    14
    That works for me. Are you sure the value of var is actually being output? If you save the following as this.php and run it you will see that it works:
    PHP Code:
    <?php
    var_dump
    ($HTTP_GET_VARS);
    ?>
    <a href="" onclick="window.open('this.php?var=test'); return false">Test</a>
    --
    Regards
    André Nęss

    Puritanism: The haunting fear that someone, somewhere may be having fun
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    Boston
    Posts
    261
    Rep Power
    13
    yeah it works, I had to put some spaces in the code so this message board wouldn't substitute the stupid smilie faces in certain places.

    The code javascript works, it opens up the specified window to the specified constraints. $var is passed thru the url to the original page and I can print it on the that page. On mouseover of the javascript openWin link it also shows page.php?var=28 (28 being the parsed $var). But when I try to print $var on the new window nothing seems to be coming thru.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    Boston
    Posts
    261
    Rep Power
    13
    ok, so andnaess, your example did work. It must have been referring back to the javascript function where the php variable got lost... I guess.

    anyway, whatever works, thanks
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    Boston
    Posts
    261
    Rep Power
    13
    I spoke to soon.

    how do you specify the parameters for the new window being openned in this way? Parameters such as size, scrolling, menu, etc...
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jul 2001
    Location
    Oslo
    Posts
    1,516
    Rep Power
    14
    Just as you would if the window.open call was made inside a function, however, it does work the same if window.open() is called from a function like you did.
    --
    Regards
    André Nęss

    Puritanism: The haunting fear that someone, somewhere may be having fun
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    Dallas, TX
    Posts
    1
    Rep Power
    0

    I hope this helps


    I am not sure if your question was answered but I hope this helps. The following code is an href that acually works. The first one is not dynamic. The value of pic is hardcoded.

    javascript:window.open('pages/history/imageViewer.php?pic=2ndAvenue','win','height=300,width=280');void(0);

    In this example the value of title is dynamic.

    viewComments.php?title=<? echo $title ?>

    Hope this helps.

IMN logo majestic logo threadwatch logo seochat tools logo