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 December 13th, 2001, 11:34 AM
bakedbean bakedbean is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: Boston
Posts: 261 bakedbean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 37 m 16 sec
Reputation Power: 12
Send a message via AIM to bakedbean
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.

Reply With Quote
  #2  
Old December 13th, 2001, 12:01 PM
realnowhereman realnowhereman is offline
Not there when you need me
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Oct 2001
Location: Berlin, Germany
Posts: 1,430 realnowhereman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 46 sec
Reputation Power: 13
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 ...

Reply With Quote
  #3  
Old December 13th, 2001, 12:06 PM
andnaess andnaess is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jul 2001
Location: Oslo
Posts: 1,516 andnaess User rank is Private First Class (20 - 50 Reputation Level)andnaess User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
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

Reply With Quote
  #4  
Old December 13th, 2001, 12:06 PM
bakedbean bakedbean is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: Boston
Posts: 261 bakedbean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 37 m 16 sec
Reputation Power: 12
Send a message via AIM to bakedbean
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.

Reply With Quote
  #5  
Old December 13th, 2001, 12:12 PM
bakedbean bakedbean is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: Boston
Posts: 261 bakedbean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 37 m 16 sec
Reputation Power: 12
Send a message via AIM to bakedbean
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

Reply With Quote
  #6  
Old December 13th, 2001, 12:15 PM
bakedbean bakedbean is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: Boston
Posts: 261 bakedbean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 37 m 16 sec
Reputation Power: 12
Send a message via AIM to bakedbean
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...

Reply With Quote
  #7  
Old December 13th, 2001, 12:25 PM
andnaess andnaess is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jul 2001
Location: Oslo
Posts: 1,516 andnaess User rank is Private First Class (20 - 50 Reputation Level)andnaess User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
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.

Reply With Quote
  #8  
Old December 13th, 2001, 05:03 PM
mpscrew mpscrew is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: Dallas, TX
Posts: 1 mpscrew User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > passing php vars through javascript

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