The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Web Design
> JavaScript Development
|
passing php vars through javascript
Discuss passing php vars through javascript in the JavaScript Development forum on Dev Shed. passing php vars through javascript JavaScript Development forum discussing JavaScript and DHTML, AJAX, and issues such as coding cross-browser JavaScript.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 13th, 2001, 11:34 AM
|
|
Contributing User
|
|
Join Date: Oct 2001
Location: Boston
Posts: 261
Time spent in forums: 9 h 37 m 16 sec
Reputation Power: 12
|
|
|
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.
|

December 13th, 2001, 12:01 PM
|
|
Not there when you need me
|
|
Join Date: Oct 2001
Location: Berlin, Germany
Posts: 1,430
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 ...
|

December 13th, 2001, 12:06 PM
|
|
Contributing User
|
|
Join Date: Jul 2001
Location: Oslo
Posts: 1,516

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
|

December 13th, 2001, 12:06 PM
|
|
Contributing User
|
|
Join Date: Oct 2001
Location: Boston
Posts: 261
Time spent in forums: 9 h 37 m 16 sec
Reputation Power: 12
|
|
|
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.
|

December 13th, 2001, 12:12 PM
|
|
Contributing User
|
|
Join Date: Oct 2001
Location: Boston
Posts: 261
Time spent in forums: 9 h 37 m 16 sec
Reputation Power: 12
|
|
|
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
|

December 13th, 2001, 12:15 PM
|
|
Contributing User
|
|
Join Date: Oct 2001
Location: Boston
Posts: 261
Time spent in forums: 9 h 37 m 16 sec
Reputation Power: 12
|
|
|
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...
|

December 13th, 2001, 12:25 PM
|
|
Contributing User
|
|
Join Date: Jul 2001
Location: Oslo
Posts: 1,516

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.
|

December 13th, 2001, 05:03 PM
|
|
Junior Member
|
|
Join Date: Dec 2001
Location: Dallas, TX
Posts: 1
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|