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

    Join Date
    Nov 2011
    Posts
    2
    Rep Power
    0

    Trouble passing variables to a popup window


    Hi guys! So I have a little bit of a problem here. I am using PHP to write out a few links onto my webpage for users to redirect to, based on the data that it pulls from my database. These links open in popup windows. The problem I am experiencing is that the variables that are passed to the popup window are the same for each link, which should not happen. I am passing information to the javascript script via GET variables that are first defined in php. However, regardless of which link the user presses, the variables are always identical. This is a problem, because each link should display a separate image in the popup window. Here is my code:

    The javascript "script":

    Code:
    <script language="javascript" type="text/javascript"> <!-- function popitup(url) { 
    
    newwindow=window.open('http://www.vgiver.com/viewgift.php?useraccess=<?php echo $userID; ?>&imagelink=<?php echo $linktopicture; ?>&friendname=<?php echo $nameoffriend; ?>&isprivate=<?php echo $isitprivate; ?>&canaccess=<?php echo $idoffriend; ?>&youraccessid=<?php echo $whosaccessid; ?>&countid=<?php echo $count; ?>','View the gift!','height=500,width=500'); 
    
    if(!newwindow){ alert('We have detected that you are using popup blocking software...');} if (window.focus) {newwindow.focus()} return false; } // --> </script>
    And now, the PHP code that defines it all:

    Code:
    for ( $count = 0; $count < sizeof($new_rows_data['picture']); $count++ ) 
    { 
    
    if ($new_rows_Private['private'][$count] == 0 || $userid == $new_rows_ID['FriendID'][$count]  || $access == $new_rows_AccessID['AccessID1'][$count]) {
    	
    $linktopicture = $new_rows_data['picture'][$count]; 
    	
    $nameoffriend = $new_rows_Name['name'][$count];
    	
    $isitprivate = $new_rows_Private['private'][$count]; 
    	
    $idoffriend = $new_rows_ID['FriendID'][$count]; 
    	
    $whosaccessid = $new_rows_AccessID['AccessID1'][$count]; 
    
    $urldirection = "http://www.vgiver.com/viewgift.php?useraccess=".$userID."&imagelink=".$linktopicture."&friendname=".$nameoffriend."&isprivate=".$isitprivate."&canaccess=".$idoffriend."&youraccessid=".$whosaccessid; 
    
    echo '<a href="#" title="'.$nameoffriend.'" onclick="return popitup()"> <img src="'.$new_rows_Wrap['wrap'][$count].'">  </a>';
    Any help would be greatly appreciated, as this is a non-negotiable feature of my program's functionality.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    112
    Rep Power
    16
    If you set your Javascript as follows
    Code:
    function popitup(url) { 
    	newwindow=window.open(url,'View the gift!','height=500,width=500'); 
    	if(!newwindow){
    		alert('We have detected that you are using popup blocking software...');
    	} 
    	if (window.focus) {
    		newwindow.focus()
    	}
    	return false;
    }
    Then change your php to pass the $urlredirection on to the popitURL like so
    Code:
    echo '<a href="#" title="'.$nameoffriend.'" onclick="return popitup('.$urldirection.')"> <img src="'.$new_rows_Wrap['wrap'][$count].'">  </a>';
    That seems to work, other wise it was just taking the last set of varibles from the loop and using them.

    Comments on this post

    • JamesNebeker agrees
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    2
    Rep Power
    0
    Thank you for the answer, this definitely helps.

IMN logo majestic logo threadwatch logo seochat tools logo