JavaScript popup_all with PHP id passing

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

JavaScript popup_all with PHP id passing

Post by evilmonkey »

Hi. I want to add to this:

Code: Select all

print"<td><a href="archive2.php?id=$row->id" target="new">$row->title</a></td>";
this:

Code: Select all

<script languarge="javascript">
popup_all('address','frame','0','0','0','0','0','yes','yes','580','420')
<script>
How would I do that? The address (in the PHP script) is "archive2.php?id=$row->id" which means it changes each time. Can the JavaScript be inserted? Also, I'm pretty sure i made a mistake in the JavaScript code :wink: .

Thanks.
f1nutter
Forum Contributor
Posts: 125
Joined: Wed Jun 05, 2002 12:08 pm
Location: London

Post by f1nutter »

Code: Select all

<?php

print("<td><a href="javascript:popup_all($row->id)">$row->title</a></td>");

?>
assuming id is a number. If it is a string, you need to enclose it in quotes.

Code: Select all

<script type="text/javascript">
function popup_all(id)
{
 window.open("archive2.php?id=" + id, "window_name", "patameters");
}
</script>
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Thanks

Post by evilmonkey »

Cool, I'll have to try it.

Yes, id is a number.

Also, does the javascript code go after the PHP code?

Thanks.
f1nutter
Forum Contributor
Posts: 125
Joined: Wed Jun 05, 2002 12:08 pm
Location: London

Post by f1nutter »

Standard layout would be to place the javascript in the head of the document. Insert that as it is above (if it works!).

Code: Select all

<html>
<head>
 <title>Title</title>
 <script ...
 </script>
</head>

<body>...
PHP will then parse the rest of your code and replace $row->id with a proper number, producing

Code: Select all

<a href="javascript:popup_all(6)">Link</a>
When you click on the link, 6 is passed to the javascript function which appends it to your link, and opens a new window with the contents of archive2.php?id=6
CodeEye
Forum Commoner
Posts: 25
Joined: Fri Jul 05, 2002 7:19 am

Post by CodeEye »

the javascript: protocol is not standard please check out
http://www.youngpup.net/?request=/artic ... popups.xml
--------------------------------------------------------------------------------

PHP:

<?php

print("<td><a href=\"javascript:popup_all($row->id)\">$row->title</a></td>");

?>



User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

Thanks guys.

I got it to work.

Cheers.
Post Reply