Page 1 of 1

JavaScript popup_all with PHP id passing

Posted: Sun Nov 03, 2002 2:53 pm
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.

Posted: Thu Nov 07, 2002 7:53 am
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>

Thanks

Posted: Thu Nov 07, 2002 12:00 pm
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.

Posted: Thu Nov 07, 2002 12:41 pm
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

Posted: Fri Nov 08, 2002 8:44 am
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>");

?>




Posted: Sat Nov 09, 2002 10:52 am
by evilmonkey
Thanks guys.

I got it to work.

Cheers.