SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot php.net's Avatar
    Join Date
    Oct 2003
    Location
    php.net
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to send a var to javascript

    hello all

    i need to know how to send var to java script popup

    index.php

    PHP Code:
    <?php
    $prog 
    mysql_query("select eid,eventTitle from events ORDER BY eid DESC LIMIT 2");
    while (list(
    $eid$eventTitle) = mysql_fetch_row($prog)) {
    ?>

    <script>
    var PopUpX = (screen.width/2)-150;
    var PopUpY = (screen.height/2)-200;
    var pos = "left="+PopUpX+",top="+PopUpY;

    function PopUp(){
    PopUpWindow = window.open("event.php?eid=<?=$eid?>","pop","width=300,height=400,"+pos);
    }
    </script>

                      <div align="center">
                        <center>
                        <table border="0" cellpadding="2" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="96%">
                          <tr>
                            <td width="100%"><a href="javascript:PopUp()"><?=$eventTitle?></a></td>
                          </tr>
                        </table>
                        </center>
                      </div>
    <?php
    }
    ?>
    event.php

    PHP Code:
    <?php
    $nz 
    mysql_query("select eid,eventTitle from events WHERE eid='$eid'");
    while (list(
    $eid$eventTitle) = mysql_fetch_row($nz)) {

    echo
    "$eventTitle";

    }
    ?>
    its not send var ( $eid ) to popup page

    any help plz

    thanks

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,033
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Well it's looking good to me in theory.

    You're opening up event.php?eid=<?php echo $eid ?>

    Make sure that you set:
    $eid = $_GET['eid'];

    Before you try and use it on your event.php page.

    I would remark out the code on event.php and just echo $eid; to make sure that I am being passed a value.

    Does that help?
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  3. #3
    SitePoint Member
    Join Date
    Aug 2001
    Location
    Florida - USA
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try

    $nz = mysql_query("select eid,eventTitle from events WHERE eid='".$_GET['eid']."'");
    talkphp.com - come join the community.

  4. #4
    SitePoint Zealot php.net's Avatar
    Join Date
    Oct 2003
    Location
    php.net
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks awasson , newedge

    i try this way but it get me first eID on all popup

    thanks
    and i wait more help

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,033
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    I expect from your code example that during the "while" loop a bunch of popups are generated. I think the real trouble here is that each iteration of the loop declares the PopUp() function.... maybe

    Anyway to avoid this I would declare the function somewhere in the header of the page (between the <head></head> tags) like so:
    Code:
    <script>
    var PopUpX = (screen.width/2)-150;
    var PopUpY = (screen.height/2)-200;
    var pos = "left="+PopUpX+",top="+PopUpY;
    
    function PopUp(URL){
    PopUpWindow = window.open(URL,"pop","width=300,height=400,"+pos);
    }
    </script>
    We'll pass the "event.php?eid=<?=$eid?>" as URL in the javascript function when you run your loop.

    Something like this:
    PHP Code:
    <?php
    $prog 
    mysql_query("select eid,eventTitle from events ORDER BY eid DESC LIMIT 2");
    while (list(
    $eid$eventTitle) = mysql_fetch_row($prog)) {
    ?> 

    <div align="center">
                        <center>
                        <table border="0" cellpadding="2" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="96%">
                          <tr>
                            <td width="100%"><a href="javascript:PopUp('event.php?eid=<?=$eid?>')"><?=$eventTitle?></a></td>
                          </tr>
                        </table>
                        </center>
                      </div>
    <?php
    }
    ?>
    During each increment $eid should change refelcting the current state.

    How's that?
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  6. #6
    SitePoint Zealot php.net's Avatar
    Join Date
    Oct 2003
    Location
    php.net
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks awasson

    thats work 100%

  7. #7
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,033
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Awsome!

    Glad that worked out for you.

    Cheers,
    Andrew
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development


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
  •