Re: populate a popup window using php and javascript
- From: The Natural Philosopher <a@xxx>
- Date: Wed, 17 Oct 2007 17:14:31 +0100
jsd219 wrote:
Hi all, I know this is an elementary question but I am at a loss. I
have googled and searched but can not find the answer. My knowledge of
javascript is infant at best and php is novice. I have a database
driven site coded in php, on the 'display_trip.php' page the user sees
a list of possible trips and with dates. I would like to code it so
when the user clicks on one of the trips a popup window opens with the
value stored in the content field of the database for that particular
trip. I have figured out how to create a popup window for images but
not how to pass info from a query.
below are snippits of my code:
File Name: display_trip.php
------------------------------------------------------------------------------------------------------------
as you can see I am calling the content field in my query.
$query = "SELECT TRIP_ID, TRIP_TITLE, TRIP_THUMB, TRIP_CONTENT
FROM TRIPS
WHERE TRIP_ID != ''";
------------------------------------------------------------------------------------------------------------
$chref = "<a class=triplink href=\"javascript:OpenEvent('";
-----------------------------------------------------------------------------------------------------------
here is part of my echo statement to create the link:
"<td align=\"left\">" . " " . "{$chref}{$row['TRIP_ID']}')
\">" . "{$row['TRIP_TITLE']} " . "</td>" .
------------------------------------------------------------------------------------------------------------
File Name: header.php file
------------------------------------------------------------------------------------------------------------
here is my javascript function from my header.php
function OpenEvent(id)
{
window.open ('SOMETHING NEED TO GO HERE' + id, 'newwindow',
config='height=450, width=550, toolbar=no, menubar=no, scrollbars=no,
resizable=no, location=no, directories=no, status=no')
}
---------------------------------------------------------------------------------------------------------------
Any help would be greatly appreciated
God bless
jason
Never mind God, jason, this is a few snippets from some code I wrote last night. It is more or less what you want.
First the PHP that sets up a clickable link. I don't use URLS as such, just a clickable field, that changes color when the mouse moves over it. That in the style sheet - the colors. I prefer to use this rather than a URL as it gives me a bit more choice on how I actually invoke the popup and get a signal back from it. In my case it actually may create change in the database which means I can force a reload if someone does a database form submit in the child process...
printf ("<TR><td height=\"25px\" ><B class=\"s3\" onclick=\"subedit('%s?id=%d')\" onmouseover=\"this.className='s4'\" onmouseout=\"this.className='s3'\">%s</b></TD>\n",
isakit($product_id[$i])? "kitedit.php":"product_edit.php",
$product_id[$i],
$partname[$i]
In practice this generates something that looks like this in the actual output HTML.
<td height="25px" ><B class="s3" onclick="subedit('product_edit.php?id=327')" onmouseover="this.className='s4'" onmouseout="this.className='s3'">part name </B></td>
Noe that the actual parameter passing is the '?id=327' bit
So now you need a javascript function to open a pop up window and invoke the file - on this case 'product_edit.php' and pass the id=327 part to it.
?>
<script type="text/javascript" language="JavaScript">
function subedit(url)
{
window.open(url,"kitedit","width=800, height=600, scrollbars=yes, resizable=yes");
}
</script>
<?
Thanks to some nice people in the comp.lang.javascript forum, this is pretty tidy and always opens a new window, even if the parent is set to open a new tab. Its a bit browser dependent., so test..test..test..
Note that any time you open a second window, it will replace the first one as both are called 'kitedit' - this is the sub-window's NAME in javascript. If it doesn't exist a new one is created,if it does it overwrites the existing one. I have made it resizable and it can have scrollbars, as I need these in many cases.
All my windows have the following code in them so that when they are called from a parent window, they will force a refresh on it if they exit, or indeed if they submit a load of data to the database..this means that changes made by spawned child windows operate in the main window instantly:-
<body onUnload="refreshDaddyPlease();">
<script type="text/javascript" language="JavaScript">
function refreshDaddyPlease()
{
if(opener!=null)
window.opener.document.forms[0].submit();
} </script>
You may not need this. I do as typically the user is editing one bit and finds he needs something that isn't there..so he can add it via a popup subswindow and magically it IS there..but it does slow things down a bit.
Ok that's nearly all the bits you need except the final bit ..How to get the variable passed by the '?id=327' bit
In the child (popup) PHP file thats simple
$id=$_GET['id'];
will load 327 int the php variable $id..when the php script is invoked as URL "product_edit.php?id=327"
Hope that all helps. Its shit being a newbie isn't it?
.
- References:
- populate a popup window using php and javascript
- From: jsd219
- populate a popup window using php and javascript
- Prev by Date: Re: populate a popup window using php and javascript
- Next by Date: Re: Do you think my site is fast enought?
- Previous by thread: Re: populate a popup window using php and javascript
- Next by thread: arrays -- can they be words, not bytes?
- Index(es):
Relevant Pages
|