JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 24th, 2011, 01:40 AM
JamesNebeker JamesNebeker is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2011
Posts: 2 JamesNebeker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 38 m 26 sec
Reputation 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.

Reply With Quote
  #2  
Old November 24th, 2011, 08:10 AM
decker27 decker27 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 84 decker27 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 43 m 32 sec
Reputation Power: 10
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!

Reply With Quote
  #3  
Old November 24th, 2011, 04:07 PM
JamesNebeker JamesNebeker is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2011
Posts: 2 JamesNebeker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 38 m 26 sec
Reputation Power: 0
Thank you for the answer, this definitely helps.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Trouble passing variables to a popup window

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap